Reputation: 274
I have the following table
Id col1 status Action
1 c R close
2 c S close
3 e R close
4 1 N close
5 2 N close
6 4 N close
I want to display all the record with the following condition
1) Action column value will only when the status is N. Otherwise it will be empty
Required output
Id col1 status Action
1 c R
2 c S
3 e R
4 1 N close
5 2 N close
6 4 N close
I am using SQL SERVER 2008 R2
Any reply will be appreciated.
Upvotes: 0
Views: 20
Reputation: 6656
Try this
SELECT Id
,col1
,STATUS
,Action = CASE
WHEN [STATUS] = 'N'
THEN [Action]
ELSE ''
END
FROM yourTable
Upvotes: 1