case
expression
Applies to: Databricks SQL Databricks Runtime
Returns resN
for the first optN
that equals expr
or def
if none matches.
Returns resN
for the first condN
evaluating to true, or def
if none found.
Syntax
CASE expr {WHEN opt1 THEN res1} [...] [ELSE def] END
CASE {WHEN cond1 THEN res1} [...] [ELSE def] END
Arguments
expr
: Any expression for which comparison is defined.optN
: An expression that has a least common type withexpr
and all otheroptN
.resN
: Any expression that has a least common type with all otherresN
anddef
.def
: An optional expression that has a least common type with allresN
.condN
: A BOOLEAN expression.
Returns
The result type matches the least common type of resN
and def
.
If def
is omitted the default is NULL.
Conditions are evaluated in order and only the resN
or def
which yields the result is executed.