8. Conditional Logic

Keywords Introduced

CASE  •  WHEN  •  THEN  •  ELSE  •  END

The main topic of this chapter is conditional logic. This term refers to an ability to infuse logic into the values that appear in specific columns in a columnlist or other expressions in a SQL statement. Based on how the logic is evaluated when the SQL statement is executed, various values can appear for a column. Thus, values that appear are conditional on the specified logic. More specifically, conditional logic is indicated by an expression that begins with the CASE keyword. This is often referred to as a CASE expression. In essence, CASE expressions allow you to alter the output presented to a user, based on logical conditions, as applied to an evaluation of ...

Get The Language of SQL, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.