SQLTeam.com | Weblogs | Forums

Multiple nested CASE statements

sql2012

#1

Hello,
is it possible to return 3 values in a switch statement? I know the following structure does not work, but is it possible to have something like this?

SELECT CASE @f1 
WHEN 1
  THEN CASE WHEN EXISTS (...)
      THEN CASE WHEN EXISTS (....)
           THEN 1
           ELSE 2
     ELSE 3
 WHEN 2 
.....

#2

You might have some syntax errors. Without seeing the full query, hard to tell. You can return 3 (or more) clauses in the same case expression.


#3

You were right, it was a syntax error. I forgot to end the nested clause.

Thank you.