Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 SSIS and Import/Export (2008)
 Switch Case Statement

Author  Topic 

arun_kumar112
Starting Member

2 Posts

Posted - 2010-05-19 : 00:56:05
Hi All,
Can i use group by statement in switch case.
Please suggest,
when i am writing this

select placement_date,
balance = CASE balance
WHEN balance BETWEEN 100 and 200 THEN 'Less than 200'
WHEN balance BETWEEN 200 and 300 THEN 'Less than 300'
ELSE 'Greater Than 300'
END,COUNT(*)
from todialer group by placement_date
it gives error

Msg 156, Level 15, State 1, Line 3
Incorrect syntax near the keyword 'BETWEEN'.

need help.

Thanks in advance,
Arun

Arun Kuma

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-05-19 : 01:43:09
2 things:

1.
CASE balance WHEN ... THEN
or
CASE WHEN balance ... THEN

2.
In your statement balance isn't grouped so you can't use it without an aggregate function like min(),max() or so..


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -