Applies to:
Status | ||||
---|---|---|---|---|
|
Status | ||||
---|---|---|---|---|
|
Status | ||||
---|---|---|---|---|
|
Status | ||||
---|---|---|---|---|
|
Description
CASE WHEN
evaluates a list of conditions and returns result expressions based on these conditions.
A CASE WHEN
statement consists of one or more conditions with associated result expressions.
Syntax
Code Block | ||||
---|---|---|---|---|
| ||||
CASE WHEN condition THEN result_expression [ WHEN condition THEN result_expression ]* ELSE result_expression END |
The result expression of the first condition that evaluates to true is returned. If no condition holds, the expression in the ELSE
part is returned. If a condition cannot be evaluated because an input column is NULL, NULL is returned.
All result expressions must be of the same type. The result type of the CASE WHEN statement is equal to the type of the result expressions.
Examples
CASE WHEN with one condition:
Panel | |||||||
---|---|---|---|---|---|---|---|
| |||||||
Column1
|
Use CASE WHEN to replace NULL values with 0.
Panel | |||||||
---|---|---|---|---|---|---|---|
| |||||||
Column1
|
Return 'even' if the input value is even, and 'odd' otherwise. NULL input values result in NULL output values:
Panel | |||||||
---|---|---|---|---|---|---|---|
| |||||||
Column1
|