The CASE statement is used in place of an expression to return a value based on other values in the query.

Syntax

CASE
  WHEN boolExpression THEN resultExpression
  [ WHEN boolExpression THEN resultExpression ] . . .
  ELSE resultExpression
END

Arguments

  • boolExpression: An expression that evaluates to a Boolean true/false value.

  • resultExpression: An expression or value to assign when boolExpression is true, or in the case of the ELSE clause, when all other

  • boolExpressions have evaluated to false.

Returns

The resultExpression.
Examples
VALUES
  CASE
    WHEN 100 < 99 THEN 0
    ELSE 1
  END