Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Applies to:  

Status
colourGreen
titleCelonis 4.0
 
Status
colourGreen
titleCelonis 4.2
 
Status
colourGreen
titleCelonis 4.3
 
Status
colourGreen
titleCelonis 4.4
 

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
languagetext
themeDJango
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
titleQuery
Column1


Code Block
languagetext
themeDJango
CASE WHEN "Table1"."Column1" = 1 THEN 2 ELSE 5 END




Panel
titleInput
Table1


Column1 : INT
1
2
1
2




Panel
titleOutput
Result


Column1 : INT
2
5
2
5











Use CASE WHEN to replace NULL values with 0.


Panel
titleQuery
Column1


Code Block
languagetext
themeDJango
CASE WHEN ( ISNULL("Table1"."Column1") = 1 ) THEN 0 ELSE "Table1"."Column1" END




Panel
titleInput
Table1


Column1 : INT
null
5
null
5




Panel
titleOutput
Result


Column1 : INT
0
5
0
5






Return 'even' if the input value is even, and 'odd' otherwise. NULL input values result in NULL output values:


Panel
titleQuery
Column1


Code Block
languagetext
themeDJango
CASE WHEN MODULO("Table1"."Column1", 2) = 0 THEN 'even' ELSE 'odd' END




Panel
titleInput
Table1


Column1 : INT
1
2
null
4
5
null




Panel
titleOutput
Result


Column1 : STRING
'odd'
'even'
'
null
'
'even'
'odd'
'
null
'