To fetch values from a column using Case statement

Posted by Anishabathija under Sql Server on 4/15/2014 | Points: 10 | Views : 1186 | Status : [Member] | Replies : 3
I have a column status which can have three possible values 0,1 and 2.

I am writing a Stored procedure and I'm fetching the values from this column and writing into a new column called progstatus using a case statement.

The condition is when it is 1 it should show active and when 0 then inactive.
however, the records with status 2 should not be fetched.

Now I have written a condition such as

Case [Status] when 0 then 'InActive' when 1 then 'Active' End as ProgStatus,

However records with status 2 is getting value "NULL".. please help modify the case statement.




Responses

Posted by: Vuyiswamb on: 4/15/2014 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
Then extend it like this


Case ISNULL([Status],0)
when 0 then 'InActive'
when 1 then 'Active'


Thank you for posting at Dotnetfunda
[Administrator]

Anishabathija, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Markconroy on: 7/28/2015 [Member] Starter | Points: 25

Up
0
Down
Case ISNULL([Status],0)
when 0 then 'InActive'
when 1 then 'Active'

This will really help you...

Anishabathija, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 7/29/2015 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi
both answer not working

try this sample code

declare @status int=0
Select Case ISNULL(@status,0)
when 0 then 'InActive'
when 1 then 'Active' END as Status


declare @status int=1
Select Case ISNULL(@status,0)
when 0 then 'InActive'
when 1 then 'Active' END as Status



Mark as Answer if its helpful to you

Kumaraspcode2009@gmail.com

Anishabathija, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response