O'Reilly logo

SQL: Visual QuickStart Guide by Chris Fehily

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

Evaluating Conditional Values with CASE

Before SQL-92, programmers complained that SQL’s lack of conditional constructs forced them to rely on the host language to take certain actions based on a condition’s truth value (true, false, or unknown). To attenuate this criticism, SQL-92 introduced the CASE expression and its shorthand equivalents, COALESCE() and NULLIF(). I’ll cover CASE in this section and the other constructs in the remainder of this chapter.

The CASE expression’s important characteristics are:

  • If you’ve programmed before, you’ll recognize that CASE provides SQL the equivalent of the if-then-else, case, or switch statements used in procedural languages, except that CASE is an expression, not a statement.

  • CASE is used to evaluate ...

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