CASE WHEN

All functions > CONDITIONAL > CASE WHEN

Returns the result of the first condition that evaluates to true

Syntax

Diagram(
    Terminal("CASE"),
    OneOrMore(
        Sequence(
            Terminal("WHEN"),
            NonTerminal("condition"),
            Terminal("THEN"),
            NonTerminal("result")
        )
    ),
    Choice(0, Skip(),
        Sequence(Terminal("ELSE"), NonTerminal("default"))
    ),
    Terminal("END")
)
ParameterTypeRequiredDescription
conditionBOOLEANYesBoolean conditions to evaluate in order
resultTYesValue to return, corresponding to each when condition
defaultTNoValue to return if no condition is true (optional)

Notes

  • Evaluates conditions in order and returns the first matching result
  • If no condition matches and else is not provided, returns NULL
  • Short-circuits: stops evaluating once a condition is true
  • All then values and else value must be of compatible types

Related Functions

Last update at: 2026/03/03 16:47:38
Last updated: 2026-03-03 16:48:19