November 17, 2010 at 2:27 am
Hi Pals,
There is a variable with 3 possible values 'ISSUED', 'PENDING', 'BOTH'
the table in the background is having bit datatype for this filed so it assumes ISSUED as 1 and PENDING as 0 through the CASE statement.
Now I want if the variable Value is 'ALL' then it consider ISSUED as well as PENDING.
Can somebody suggest anything?
DECLARE @status Varchar (10)
SELECT @status='ALL'
--following is the part of select statement I have written
CASE @status WHEN 'ISSUED' THEN 1
WHEN 'PENDING' THEN 0
WHEN 'ALL' THEN --I need help here as I want the rows matching either 1 or 0
Thanks
November 17, 2010 at 2:35 am
So what should be the o/p when variable value is ALL?
--------------------------------------------------------------------------------------------------
I am just an another naive wannabe DBA trying to learn SQL Server
November 17, 2010 at 2:37 am
November 17, 2010 at 2:38 am
It would be helpful if you post the complete SELECT query at least
But i think this is what you want.
DECLARE @status Varchar (10)
SELECT @status='ALL'
--following is the part of select statement I have written
CASE @status WHEN 'ISSUED' THEN 1
WHEN 'PENDING' THEN 0
WHEN 'ALL' THEN <name of the column> -- Enter the name of the column here
How to post data/code on a forum to get the best help - Jeff Moden
http://www.sqlservercentral.com/articles/Best+Practices/61537/
November 17, 2010 at 2:45 am
Kingston Dhasian (11/17/2010)
It would be helpful if you post the complete SELECT query at leastBut i think this is what you want.
DECLARE @status Varchar (10)
SELECT @status='ALL'
--following is the part of select statement I have written
CASE @status WHEN 'ISSUED' THEN 1
WHEN 'PENDING' THEN 0
WHEN 'ALL' THEN <name of the column> -- Enter the name of the column here
Aah. I did not know that it would have this much easy...
Thanks Kingston you fixed this. I appreciate your quick help.
November 17, 2010 at 2:53 am
Glad i could help you out 🙂
How to post data/code on a forum to get the best help - Jeff Moden
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply