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
 Variation of Case Condition

Author  Topic 

ewan
Starting Member

13 Posts

Posted - 2011-12-14 : 02:34:43

Can somebody tell what are the variation of case condition?

It's gonna be a big help.

Thanks.



jeneca

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-14 : 03:44:08
mainly two variations

simple case expression like

CASE <search expression>
WHEN <somevalue> THEN <some return expression>
WHEN <somevalue2> THEN <some return expression2>
WHEN <somevalue3> THEN <some return expression3>
...
ELSE <some return expressionn>
END

and

Searched CASE expression:
CASE
WHEN <boolean expression> THEN <some return expression>
WHEN <boolean expression2> THEN <some return expression2>
WHEN <boolean expression3> THEN <some return expression3>
WHEN <boolean expression4> THEN <some return expression4>
ELSE <some return expressionn>
END


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

ewan
Starting Member

13 Posts

Posted - 2011-12-14 : 21:31:58
What about if you're gonna put the results in diff. columns. It's like in every "WHEN <boolean expression> THEN <some return expression>", you're going to assign a column name on it?



jeneca
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2011-12-14 : 22:08:15
A CASE expression returns a single value, so it can only go in one column.



CODO ERGO SUM
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-14 : 23:50:38
quote:
Originally posted by ewan

What about if you're gonna put the results in diff. columns. It's like in every "WHEN <boolean expression> THEN <some return expression>", you're going to assign a column name on it?



jeneca



CASE is not a control flow statement but its just an expression which conditionally returns a value in a resultset

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -