Can anyone tell me what I'm doing wrong with the following code; I'm getting 'Server: Msg 156, Level 15, State 1, Line 4
Incorrect syntax near the keyword 'case'.' when I check the syntax.
declare @dayofweek tinyint
declare @tuesday date
set @dayofweek = datepart(dw,getdate())
case @dayofweek
when 1 then @tuesday=dateadd(d,-5,getdate())
when 2 then @tuesday=dateadd(d,-6,getdate())
when 3 then @tuesday=getdate()
when 4 then @tuesday=dateadd(d,-1,getdate())
when 5 then @tuesday=dateadd(d,-2,getdate())
when 6 then @tuesday=dateadd(d,-3,getdate())
when 7 then @tuesday=dateadd(d,-4,getdate())
end
Also, if there's an easier way of finding out what the previous Tuesday's date was, I'm open to suggestions.
Thanks,
JC
Incorrect syntax near the keyword 'case'.' when I check the syntax.
declare @dayofweek tinyint
declare @tuesday date
set @dayofweek = datepart(dw,getdate())
case @dayofweek
when 1 then @tuesday=dateadd(d,-5,getdate())
when 2 then @tuesday=dateadd(d,-6,getdate())
when 3 then @tuesday=getdate()
when 4 then @tuesday=dateadd(d,-1,getdate())
when 5 then @tuesday=dateadd(d,-2,getdate())
when 6 then @tuesday=dateadd(d,-3,getdate())
when 7 then @tuesday=dateadd(d,-4,getdate())
end
Also, if there's an easier way of finding out what the previous Tuesday's date was, I'm open to suggestions.
Thanks,
JC