CASE expressions allow conditional processing in EQL, allowing you to make decisions at query time.
The syntax of the CASE expression, which conforms to the SQL standard, is:
CASE WHEN <Boolean expression> THEN <expression> [WHEN <Boolean expression> THEN <expression>]* [ELSE expression] END
CASE expressions must include at least one WHEN expression. The first WHEN expression with a TRUE condition is the one selected. NULL is not TRUE. The optional ELSE clause must always come at the end of the CASE statement and is equivalent to WHEN TRUE THEN. If no condition matches, the result is NULL.
In this example, division by non-positive integers is avoided:
CASE WHEN y < 0 THEN x / (0 - y) WHEN y > 0 THEN x / y ELSE 0 END
RETURN Result AS SELECT CASE WHEN (Days < 7) THEN 'Recent' ELSE ‘Old’ END AS Age
RETURN CaseExample AS SELECT CASE WHEN Class = 'H' THEN MIN(DealerPrice) WHEN Class = 'M' THEN MIN(ListPrice) ELSE MIN(StandardCost) END AS value GROUP BY Class