Chapter 11. CASE Expressions

THE CASE EXPRESSION IS probably the most useful addition in SQL-92. This is a quick overview of how to use the expression, but you will find other tricks spread throughout the book.

The reason it is so important is that:

1.It works with any data type.
2.It allows the programmer to avoid procedural code by replacing IF-THEN-ELSE control flow with CASE expression inside the query.
3.It makes SQL statements equivalent to primitive recursive functions. You can look up what that means in a book on the theory of computation, but it is a nice mathematical property that guarantees certain kinds of problems can be solved.

Get Joe Celko's SQL for Smarties, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.