CASE
Syntax
<case-expression> := 'CASE(' <Boolean> ',' <Any> { ',' <Boolean> ',' <Any> } ')'
Since
2.2.2
Return-type
The return-type is the super-type of all values.
Description
The CASE-function allows the conditional evaluation of one or more arguments. The CASE-function is very similar to the IIF function but accepts more than one condition.
Beginning with the first argument (which must be a boolean condition), the system evaluates the condition. If the condition returns TRUE, the following argument is evaluated and its result is returned as the result of the CASE function. If it returns FALSE, then the following condition (the third argument) is evaluated and so on.
If any of the evaluated conditions returns NULL then the function returns NULL. If no condition return TRUE or NULL the function also returns NULL.
Because there is no default return-value for this CASE function, you may add TRUE as the last condition, followed by the default value. Then this condition will always be returned if no other condition matches.
Examples
CASE( HASLEVEL( Time, 1 ), 'L1', HASLEVEL( Time, 2 ), 'L2', TRUE, 'Other' )
Returns 'L1' for years, 'L2' for months and 'Other' for any other level of the current time-selection.
CASE( HASLEVEL( Time, 1 ), 'L1', NULL, 'L2' )
Returns 'L1' for years and NULL for any other level of the time selection.
See also
IIF
