O'Reilly logo

Microsoft® SQL Server™ 2000 Programming by Example by Carlos Eduardo Rojas, Fernando G. Guerrero

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The CASE Function

You can use the CASE function to provide conditional values to an expression.

Caution

You cannot use the CASE function to provide conditional execution of statements as in other programming languages.

The result of a CASE function is always a scalar value. You can use CASE in two different ways:

  • Select a result depending on the possible values that a variable, column, or expression can have. This is called Simple CASE. CASE returns the value correspondent to the first value that is equal to the searched expression. Listing 11.16 contains three examples using the CASE function to provide a verbose output.

  • The CASE function evaluates in sequence several independent conditions. The CASE function returns the result correspondent ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required