---
schema_version: "1"
id: 38984a414e723c24daf5b4a0617b8096a87c821fda3b2669804ed298893015fc
title: CASE Statements
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/analytics/bi_dev_guide_sql/guides/bi-sql-case.md
canonical_url: https://developer.salesforce.com/docs/analytics/bi-dev-guide-sql/guide/bi-sql-case.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: da7c97212a4a51809608d6d00d5fbd27fc98f8f46a36d410214cde104abe426f
products:
  - SQL for Analytics Developer Guide
  - analytics
---

# CASE Statements

Use case statements to express if/then logic. A case statement always has a pair of `WHERE` and `THEN` statements. CRM Analytics supports the simple and searched forms of case expressions in a `SELECT` statement. Case statements have two formats: simple and searched.

## Simple Form

A simple statement compares a case expression against a set of expressions. The result is the matched expression.

```nolang
SELECT Category, CASE Category
WHEN 'Furniture' THEN 'Available'
WHEN 'Office Supplies' THEN 'Unavailable'
ELSE 'Unknown' END AS Availability
FROM "Superstore"
GROUP BY Category;
```

Here are the results.

| Category        | Availability |
| --------------- | ------------ |
| Furniture       | Available    |
| Office Supplies | Unavailable  |
| Technology      | Unknown      |

## Searched Form

The searched form evaluates to a result. A searched statement compares an expression against a series of boolean expressions. If it matches a boolean expression, the result is the corresponding THEN clause. If the expression does not return true for any of the boolean expressions, then the result is the corresponding `ELSE` clause.

```nolang
SELECT Region, CASE
WHEN sum(Profit) <= -500000 THEN 'Huge Loss'
WHEN sum(Profit) <= 0 THEN 'Loss'
WHEN sum(Profit) > 500000 THEN 'Huge Profit'
ELSE 'Profit' END AS ProfitLoss
FROM "Superstore"
GROUP BY Region;
```

| Region  | ProfitLoss |
| ------- | ---------- |
| Central | Profit     |
| East    | Profit     |
| South   | Profit     |
| West    | Profit     |
