case statement with or | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

case statement with or

Hi, I have a table tblStatu with columns ID Name Status
1 Yellow Active
2 Red Active
3 Green Inactive
4 Blue REmoved Now i wrote a sql statement as Select * from tblStatus where
Status = case @Filter when 0 then ‘Active’ else (‘Active’ OR ‘InActive’) end
but the or is throwing the error, I dont know why.
Basically I want do this when filter = 0 then select all the row where status is active
else id status is what ever then select all the row where status is active or inactive
Thanks
Select * from tblStatus where
Status = case @Filter when 0 then ‘Active’ else Status end MohammedU.
Moderator
SQL-Server-Performance.com All postings are provided “AS IS” with no warranties for accuracy.

Hi
I tried using the sql statement, but it will select all, which I dont want
for example ‘removed’ should’t be selected.
I just want rows which are active and inactive.
Thanks for the reply…
Select * from tblStatus where
(@Filter = 0 AND Status = ‘Active’)
OR (@Filter <> 0 AND Status IN(‘Active’,’InActive’))
Roji. P. Thomas
SQL Server MVP
http://toponewithties.blogspot.com

Thanks so much, it works like magic <img src=’/community/emoticons/emotion-1.gif’ alt=’:)‘ />
Thanks for the acknowledgement. Roji. P. Thomas
SQL Server MVP
http://toponewithties.blogspot.com

]]>