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.
| Author |
Topic |
|
elwoos
Master Smack Fu Yak Hacker
2052 Posts |
Posted - 2003-12-23 : 09:35:17
|
| I'm sure I'm missing something blindingly obvious but have looked all over with no success. I have a sproc which takes two parameters. I wanted them to default to the current date (i.e. getdate()) but that didn't work and BOL suggested that the defaults have to be constants.I now have:-CREATE PROCEDURE sproc_RMSReferrals @StartMonth datetime, @EndMonth datetime AS...when I try to runexec sproc_RMSReferrals getdate(), getdate()in Query Analyzer I get an errorLine 1: Incorrect syntax near ')'.What's going on?steveSteve no function beer well without |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2003-12-23 : 09:41:20
|
| You can't call an SP with a function as parameterdeclare @d datetimeselect @d = getdate()exec sproc_RMSReferrals @d, @dIf you want it to default thenCREATE PROCEDURE sproc_RMSReferrals@StartMonth datetime = null, @EndMonth datetime = nullASselect @StartMonth = coalesce(@StartMonth ,getdate()) ,@EndMonth = coalesce(@EndMonth ,getdate()) ,...==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
raymondpeacock
Constraint Violating Yak Guru
367 Posts |
Posted - 2003-12-23 : 09:42:07
|
| SteveGet around the constants by declaring the parameters with NULL defaults, then assigning them the GETDATE() default in the stored proc.Try thisCREATE PROCEDURE sproc_RMSReferrals(@StartMonth datetime = NULL, @EndMonth datetime = NULL)ASBEGINSELECT @StartMonth = ISNULL(@StartMonth, GETDATE())SELECT @EndMonth = ISNULL(@EndMonth, GETDATE())...Then to call it with defaults used, tryEXEC sproc_RMSReferralsRaymond |
 |
|
|
mohdowais
Sheikh of Yak Knowledge
1456 Posts |
Posted - 2003-12-24 : 00:29:47
|
You could also:DECLARE @StartDate DATETIMEDECLARE @EndDate DATETIMESET @StartDate = GETDATE()SET @EndDate = GETDATE()EXEC sproc_RMSReferrals @StartDate, @EndDate OwaisWe make a living out of what we get, but we make a life out of what we give. |
 |
|
|
|
|
|
|
|