SQL CASE Expression

From Logic Wiki
Revision as of 14:27, 9 May 2016 by Dt1nh6 (Talk | contribs) (1 revision imported)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


Evaluates a list of conditions and returns one of multiple possible result expressions. The CASE expression has two formats:

Simple CASE expression

The simple CASE expression compares an expression to a set of simple expressions to determine the result.

CASE input_expression 
    WHEN when_expression THEN result_expression [ ...n ] 
    [ ELSE else_result_expression ] 
END 

Searched CASE expression

The searched CASE expression evaluates a set of Boolean expressions to determine the result. Both formats support an optional ELSE argument.

CASE
    WHEN Boolean_expression THEN result_expression [ ...n ] 
    [ ELSE else_result_expression ] 
END