`CASE`
Data 360 Query Guide, mirrored from developer.salesforce.com: **Applies to:** ✅ Data 360 SQL ✅ Tableau Hyper API
markdownreferencev1Z868-XS1Cguide: data-cloud-query-guidestage: referencetrust: officialsource: developer.salesforce.comservice: data360interface: sql`CASE`Data 360Data CloudData 360 Query Guide
Mirror of <https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/case.html> (Salesforce, Data 360 Query Guide), read 2026-10-23. Salesforce's own page is the authority; this copy exists because that site refuses non-browser readers.
CASE
Applies to: ✅ Data 360 SQL ✅ Tableau Hyper API
The CASE expression is a generic conditional expression, similar to if/else statements in other programming languages. Use a CASE expression wherever an expression is valid.
CASE has two variants.
In the first variant:
<condition>: An expression that returns a boolean result. The<condition>of eachWHENclause is evaluated in order until one returns true.
In the second variant:
<expression>: An expression that’s computed once and then compared to the<value>of eachWHENclause.<value>: A value to compare against<expression>.
In both variants:
<result>: The value returned when the associatedWHENclause matches.
ELSE <result>: The value returned when noWHENclause matches. If theELSEclause is omitted and no clause matches, then the result isNULL.
Returns the <result> of the first matching WHEN clause. If no clause matches, returns the ELSE result, or NULL if there’s no ELSE clause.
In the first variant, if a condition returns true, the value of the CASE expression is the <result> that follows the condition, and the rest of the expression isn’t processed. If the condition isn’t true, the expression examines subsequent WHEN clauses in the same manner.
In the second variant, called a simple CASE expression, <expression> is computed and then compared to each <value> until an equal value is found.
- A
CASEexpression evaluates only the subexpressions that are required to determine the result. For example, thisCASEexpression is a potential way to avoid a division-by-zero failure:
- The data types of all
<result>expressions must be convertible to a single output type.
- In a simple
CASEexpression, aNULLinput never equals anyWHENvalue, so the expression returns theELSEresult, orNULLif there’s noELSEclause.
These examples use this test table:
Use the first variant to map each value to a label.
Returns the result:
Use the simple CASE expression to write the previous example more concisely.
Returns the same result.