开发者

SQL Server CASE statement error: Incorrect syntax near '<'

开发者 https://www.devze.com 2023-03-27 22:46 出处:网络
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:

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

0

精彩评论

暂无评论...
验证码 换一张
取 消