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 |
|
yawnzzzz
Starting Member
13 Posts |
Posted - 2011-06-16 : 12:00:23
|
Hi,I'm creating a Store Procedure where the user will be submitting some information along with a date. If the date isn't submitted, then I want to use the current date, but when I try to do this it throw an error: Incorrect Syntax near ')'.CREATE PROCEDURE [user_rw].[UpdateSomething] @SomeID int out, @EffectiveDate datetimeASBEGIN SET NOCOUNT ON; IF @EffectiveDate is NULL BEGIN SET @EffectiveDate = GetDate(); --Error here END BEGIN --Other Code ENDEND |
|
|
yawnzzzz
Starting Member
13 Posts |
Posted - 2011-06-16 : 12:02:46
|
| Sorry, nevermind. Error was somewhere else, and it just happened to be pointing at that line by mistake. |
 |
|
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2011-06-17 : 01:52:58
|
| CREATE PROCEDURE [user_rw].[UpdateSomething] @SomeID int out, @EffectiveDate datetimeASBEGIN SET NOCOUNT ON; IF @EffectiveDate is NULL BEGIN SET @EffectiveDate = GetDate(); --Error here END Else BEGIN --Other Code ENDENDSenthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/ |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2011-06-20 : 12:15:20
|
The conditionIF @EffectiveDate is NULL BEGIN SET @EffectiveDate = GetDate(); --Error here END can be simplified toset @EffectiveDate =coalesce(EffectiveDate,getdate())MadhivananFailing to plan is Planning to fail |
 |
|
|
jeffw8713
Aged Yak Warrior
819 Posts |
Posted - 2011-06-20 : 15:46:59
|
I would also make the parameter optional...CREATE PROCEDURE [user_rw].[UpdateSomething]@SomeID int out,@EffectiveDate datetime = NULLAS And, if you are passing in a date with time and don't want the time:SET @EffectiveDate = dateadd(day, datediff(day, 0, coalesce(@EffectiveDate, getdate())), 0);Jeff |
 |
|
|
|
|
|
|
|