I'll put you out of your misery: No, you can't. My guess here is that either you want both variables to be exactly the same (eliminating any possibility of two calls to GETDATE()
returning different values, however small), or you just want fewer function calls. SQL Server doesn't support syntax like
SET @StartDate = @EndDate = GETDATE()
That's even leaving aside the implicit narrowing from DATETIME
to DATE
(althoguh that's not really an issue). Best you can do is
SET @StartDate = GETDATE()
SET @EndDate = @StartDate
Unless you just want to save a line in which case you can comma separate the @Variable = GETDATE()
calls and only use one SELECT
.
EDIT
Forgot to add this example - could reduce to one line thus:
SELECT @EndDate = GETDATE(), @StartDate = @EndDate