Hello Everyone,
I need to use a case statement in the where clause and I can't seem to get this to work. I don't think I'm using this correctly. My statement looks something like this:
Declare @FYDFrom as DateTime,
@FYDTo as DateTime,
@FYDFrom1 as DateTime,
@FYDTo1 as DateTime
Set @FYDFrom = '20090701'
Set @FYDTo = '20100701'
Set @FYDFrom1 = '20100701'
Set @FYDTo1 = '20110701'
SELECT *
FROM charges c
Where
Case When GetDate() < '20100701'
Then c.create_timestamp >= @FYDFrom and c.create_timestamp < @FYDTo
When GetDate() >= '20100701'Then c.create_timestamp >= @FYDFrom1 and c.create_timestamp < @FYDTo1
End
The error message I receive is Msg 102, Level 15, State 1, Line 16
Incorrect syntax near '>'
Any help would be appreciated!
Thanks!
I need to use a case statement in the where clause and I can't seem to get this to work. I don't think I'm using this correctly. My statement looks something like this:
Declare @FYDFrom as DateTime,
@FYDTo as DateTime,
@FYDFrom1 as DateTime,
@FYDTo1 as DateTime
Set @FYDFrom = '20090701'
Set @FYDTo = '20100701'
Set @FYDFrom1 = '20100701'
Set @FYDTo1 = '20110701'
SELECT *
FROM charges c
Where
Case When GetDate() < '20100701'
Then c.create_timestamp >= @FYDFrom and c.create_timestamp < @FYDTo
When GetDate() >= '20100701'Then c.create_timestamp >= @FYDFrom1 and c.create_timestamp < @FYDTo1
End
The error message I receive is Msg 102, Level 15, State 1, Line 16
Incorrect syntax near '>'
Any help would be appreciated!
Thanks!