SQLTeam.com | Weblogs | Forums

Checks in each column for valid value

sql2008

#1

Respected Techie,

Can we have subquery inside a case statement.


#2

Yes, providing the subquery always only returns one value. However that may or may not be the best way to do things. It would be helpful if you posted your query with proposed changes so others could offer alternatives.

BTW, when I have a question like yours, "Can we have subquery inside a case statement." I usually just try something simple to see if SQL lets me do it, e.g.

SELECT CASE (SELECT 1) WHEN 1 THEN 'ONE' END

runs fine with no errors, Therefore I know that I can put a subquery in a case expression

BTW, CASE is an expression, not a statement. Subtle distinction, but important. Anywhere you can put an expression, you can put a CASE expression.