
The example above can be written using the simple CASE syntax:Ī CASE expression does not evaluate any subexpressions that are not needed to determine the result. This is similar to the switch statement in C. If no match is found, the result of the ELSE clause (or a null value) is returned. The first expression is computed, then compared to each of the value expressions in the WHEN clauses until one is found that is equal to it. There is a “ simple” form of CASE expression that is a variant of the general form above: The data types of all the result expressions must be convertible to a single output type. If the ELSE clause is omitted and no condition is true, the result is null. If no WHEN condition yields true, the value of the CASE expression is the result of the ELSE clause. If the condition's result is not true, any subsequent WHEN clauses are examined in the same manner. Each condition is an expression that returns a boolean result. ELSE result END CASE clauses can be used wherever an expression is valid. If the condition's result is true, the value of the CASE expression is the result that follows the condition, and the remainder of the CASE expression is not processed. CASE The SQL CASE expression is a generic conditional expression, similar to if/else statements in other programming languages: CASE WHEN condition THEN result WHEN.


The SQL CASE expression is a generic conditional expression, similar to if/else statements in other programming languages:ĬASE clauses can be used wherever an expression is valid.
