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.
I need to set default values for 2 parms in my SP. So I do this:SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOCREATE PROCEDURE FirstDataReport -- Add the parameters for the stored procedure here @month int = DATEPART(month,GETDATE()), @year int = DATEPART(year,GETDATE())ASBEGINWhen I do this, I get:Msg 102, Level 15, State 1, Procedure FirstDataReport, Line 3Incorrect syntax near '('.On the @month declaration. Can anyone shed any light here?Thanks!Mike
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2009-06-09 : 12:33:43
you cant give expressions for default value of sp. you can do it like this however
SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOCREATE PROCEDURE FirstDataReport -- Add the parameters for the stored procedure here@month int = NULL, @year int = NULLASBEGINSELECT @month=COALESCE(@month,DATEPART(month,GETDATE())),@year=COALESCE(@year,DATEPART(year,GETDATE()))