This guide is specifically for SQL Server syntax.
Intermediate-level SQL CASE WHEN practice exercises with solutions.
Exercise 1
Question: Categorize employees by salary range (Low, Medium, High).
SELECT name, salary, CASE WHEN salary < 40000 THEN 'Low' WHEN salary BETWEEN 40000 AND 70000 THEN 'Medium' ELSE 'High' END AS salary_category FROM employees;
CASE WHEN provides if-then-else logic in SQL. ELSE handles all unmatched conditions.
SQL Server-Specific Notes
This page covers SQL Server syntax. Other databases may have different syntax for similar operations.