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 2005 Forums
 Transact-SQL (2005)
 Select iif .............

Author  Topic 

pragneshmpatel@gmail.com
Starting Member

3 Posts

Posted - 2008-05-29 : 10:17:24
hi all,
I want to user "If ElseIf else .." in Select Statement with Group By .

The Following statement is working in MS Access. Which got only If Else. But i want to implement same thing with more condition in Sql 2005.

SELECT IIf([Water Depth (M)]<500,"<500",">=500") AS DEPTH, Count([Operator Name]) AS [CountOfOperator Name],
FROM [tblDepth]
GROUP BY IIf([Water Depth (M)]<500,"<500",">=500");

Waiting for any help!!

Thanks
Pragnesh

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-05-29 : 10:21:24
SELECT case when [Water Depth (M)]<500 then '<500' else '>=500' end AS DEPTH, Count([Operator Name]) AS [CountOfOperator Name],
FROM [tblDepth]
GROUP BY case when [Water Depth (M)]<500 then '<500' else '>=500' end


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

pragneshmpatel@gmail.com
Starting Member

3 Posts

Posted - 2008-05-29 : 10:26:48
Thanks
Madhivanan

It Works!!

SELECT case when [Water Depth (M)]<500 then '<500'
when [Water Depth (M)]>500 then '>500'
else '>=500' end AS DEPTH, Count([Operator Name]) AS [CountOfOperator Name]
FROM [tblDepth]
GROUP BY case when [Water Depth (M)]<500 then '<500'
when [Water Depth (M)]>500 then '>500' else '>=500' end
Go to Top of Page
   

- Advertisement -