Question on Merging two cases

  • 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

    -Forum Etiquette: How to post Performance Problems[/url]

    -Forum Etiquette: How to post data/code to get the best help [/url]

  • 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

  • Sachin Nandanwar (11/17/2010)


    So what should be the o/p when variable value is ALL?

    it needs to be both the values either 1 or 0 (means all the rows either ISSUED or PENDING)

    -Forum Etiquette: How to post Performance Problems[/url]

    -Forum Etiquette: How to post data/code to get the best help [/url]

  • 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


    Kingston Dhasian

    How to post data/code on a forum to get the best help - Jeff Moden
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

  • Kingston Dhasian (11/17/2010)


    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

    Aah. I did not know that it would have this much easy...

    Thanks Kingston you fixed this. I appreciate your quick help.

    -Forum Etiquette: How to post Performance Problems[/url]

    -Forum Etiquette: How to post data/code to get the best help [/url]

  • Glad i could help you out 🙂


    Kingston Dhasian

    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