Conditional expression returning different values based on evaluated conditions.
The SQL conditional expression, supporting searched CASE (WHEN condition THEN result) and simple CASE (WHEN expression = value THEN result). Used for pivot-like transformations, conditional aggregation, and business rule encoding. Evaluate NULLIF and COALESCE first for simpler cases.
| Database System | Support Status | Since Version | Notes |
|---|---|---|---|
| MySQL | ✓ Supported | all | Both simple and searched CASE. Also supports IF(condition, true_val, false_val) and IIF() as a 2-arg shorthand. |
| PostgreSQL | ✓ Supported | all | Both simple and searched CASE. CASE can appear in SELECT, WHERE, ORDER BY, HAVING, and aggregate arguments. |
| SQL Server | ✓ Supported | all | Both simple and searched CASE. Also IIF(condition, true_val, false_val) since SQL Server 2012. |
| Oracle | ✓ Supported | all | Both simple and searched CASE. Legacy DECODE(expr, search, result, ...) function also works. |
| SQLite | ✓ Supported | all | Both simple and searched CASE fully supported. |
CASE is SQL-standard and works identically across all major engines. Dialect-specific shorthands (IF, IIF, DECODE) exist but are not portable.
Both simple and searched CASE. Also supports IF(condition, true_val, false_val) and IIF() as a 2-arg shorthand.
Both simple and searched CASE. CASE can appear in SELECT, WHERE, ORDER BY, HAVING, and aggregate arguments.
Both simple and searched CASE. Also IIF(condition, true_val, false_val) since SQL Server 2012.
Both simple and searched CASE. Legacy DECODE(expr, search, result, ...) function also works.
Both simple and searched CASE fully supported.