Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to use case in a select statement

Author  Topic 

insanepaul
Posting Yak Master

178 Posts

Posted - 2010-11-11 : 11:46:05
I want to do something like the code below on a much more complex stored procedure. Basically I want to display cell 'b' from Table X if the cell a is a certain value else null


SELECT
X.a,
X.b case(X.a = 5 or X.a is null then X.b... ELSE NULL) as [VAT],
X.c
FROM X



Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2010-11-11 : 11:56:28
That's close. Try this:
SELECT
X.a,
CASE
WHEN X.a = 5 OR X.a IS NULL
THEN X.b
ELSE
NULL
END AS VAT,
X.c
FROM X
Go to Top of Page

insanepaul
Posting Yak Master

178 Posts

Posted - 2010-11-11 : 12:17:09
quote:
Originally posted by Lamprey

That's close. Try this:
SELECT
X.a,
CASE
WHEN X.a = 5 OR X.a IS NULL
THEN X.b
ELSE
NULL
END AS VAT,
X.c
FROM X




Great that did the trick thanks
Go to Top of Page
   

- Advertisement -