---
cuppy_hub: salesforce
cuppy_path: reference/official/data360/data-cloud-query-guide/references/dc-sql-reference/case.md
cuppy_section: docs
cuppy_doc: Z868-XS1C
cuppy_doc_uuid: eeec7c90-3450-49a3-8ddd-f561455c08e6
cuppy_permalink: https://cuppy.io/salesforce/d/Z868-XS1C
cuppy_version: 1
cuppy_updated: 2026-10-23T16:16:52.575Z
cuppy_canonical: https://cuppy.io/salesforce/docs/reference/official/data360/data-cloud-query-guide/references/dc-sql-reference/case
cuppy_mcp: https://cuppy.io/mcp
cuppy_body_sha256: 496421be1ae7fd500ddea6fed75e7ace41298841d49025d80248fc97b2f94cbf
# cuppy_body_sha256 is over the document body ALONE, excluding both generated blocks.
---

> 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.

*   [COALESCE](https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/coalesce.html)
*   [NULLIF](https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/nullif.html)
*   [Conditional Expressions](https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/conditional-func.html)


---
<!-- cuppy -->
You are reading one file. The same content is free over MCP at https://cuppy.io/mcp with no signup: ranked search across all 376 documents in this hub, the merged view when you work in a layer, known workarounds matched to the error you hit, and depth control so you spend tokens on what you need. Start with the `_hello` tool. How to connect: https://cuppy.io/salesforce/ Something wrong in this document? Report it with the `session feedback` tool on the same endpoint.
<!-- /cuppy -->
