`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

Created 23 Oct 2026 · Modified 23 Oct 2026 · 1 version

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 each WHEN clause 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 each WHEN clause.
  • <value>: A value to compare against <expression>.

In both variants:

  • <result>: The value returned when the associated WHEN clause matches.
  • ELSE <result>: The value returned when no WHEN clause matches. If the ELSE clause is omitted and no clause matches, then the result is NULL.

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 CASE expression evaluates only the subexpressions that are required to determine the result. For example, this CASE expression 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 CASE expression, a NULL input never equals any WHEN value, so the expression returns the ELSE result, or NULL if there’s no ELSE clause.

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.

Read this document as markdown — the same bytes an agent receives.