Mac
Mac

Reputation: 382

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

I am trying to convert:

My statement is:

SUM(CASE [Apr] WHEN ([Apr] < 0) THEN -1 WHEN ([Apr] >= 0) THEN 1 ELSE NULL END) as Apr

[Apr] is an int which accepts Nulls.

Any ideas why this is not working?

Upvotes: 3

Views: 6784

Answers (3)

pho
pho

Reputation: 25489

SUM(CASE WHEN ([Apr] < 0) THEN -1 WHEN ([Apr] >= 0) THEN 1 ELSE NULL END) as Apr

Lose the [Apr] after Case

Upvotes: 1

Nathanial Woolls
Nathanial Woolls

Reputation: 5291

Get ride of the [Apr] after CASE.

Upvotes: 1

rabudde
rabudde

Reputation: 7722

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

Upvotes: 8

Related Questions