SQL Server CASE statement error: Incorrect syntax near '<'
I am trying to convert:
- any number less than 0 to a -1.
- any number greater than or equal to 0 to a 1.
My statement is:
SUM(CASE [Apr] WHEN ([Apr] < 0) THEN -1 WHEN ([Apr] >= 0) THEN 1 ELSE NULL END) as Apr
[Apr]
开发者_Python百科 is an int which accepts Nulls.
Any ideas why this is not working?
Remove [Apr]
after CASE
when doing comparisions in WHEN
SUM(CASE WHEN ([Apr] < 0) THEN -1 WHEN ([Apr] >= 0) THEN 1 ELSE NULL END) as Apr
Get ride of the [Apr] after CASE.
SUM(CASE WHEN ([Apr] < 0) THEN -1 WHEN ([Apr] >= 0) THEN 1 ELSE NULL END) as Apr
Lose the [Apr] after Case
精彩评论