Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
quote:Originally posted by tkizer Because it isn't allowed. Do that after the AS.
Ah yeah that worked, thanks.
ALTER PROCEDURE dbo.sp_NAME( @T1 DATETIME = NULL, @T2 DATETIME = NULL)ASIF @T1 IS NULL BEGIN SET @T1 = '1/1/' + CAST(DATEPART(YEAR,GETDATE()) AS VARCHAR(4)) ENDIF @T2 IS NULL BEGIN SET @T2 = GETDATE() END...
Note that you are relying on an implicit date cast - which depends on the Locale of your server (which could conceivably change, over time).My preference would be to use yyyymmdd format, which is the only date format which will implicitly cast unambiguously, but for good measure I've put an explicit CAST in too :
IF @T1 IS NULL BEGIN SET @T1 = CAST(CAST(DATEPART(YEAR,GETDATE()) AS VARCHAR(4)) + '0101') AS DATETIME END