# CASE / WHEN in T-SQL

CASE picks a value by conditions, like if and else if. Use it to label rows, to count only the rows that match with SUM(CASE ...), and to sort in a custom order.

![Cheat sheet: CASE / WHEN in T-SQL](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/11/ab6656e3228d4ba98cab169b2d04f8a8.webp)

- Category: SQL
- Level: Journeyman
- Tags: CASE Expression, sql, t-sql
- Updated: November 3, 2026

Source: https://www.ask-codey.com/cheat-sheets/case-when-in-t-sql-cheat-sheet
