A simple CASE expression compares one expression with multiple possible values and returns the corresponding result for the first match.
Simple CASE is useful when one column or expression needs to be mapped into readable business categories.
Convert department codes into department names.
SELECT
EmployeeName,
CASE DepartmentCode
WHEN 'IT' THEN 'Information Technology'
WHEN 'HR' THEN 'Human Resources'
WHEN 'FN' THEN 'Finance'
ELSE 'Other'
END AS DepartmentName
FROM Employees;
Simple CASE is useful for mapping codes, statuses, categories, and standardized business labels.
- Simple CASE compares one expression.
- Multiple values can be checked.
- Each value can have a different result.
- ELSE handles unmatched values.
- It is useful for code-to-label mapping.
What is simple CASE?
Simple CASE compares one expression against multiple values and returns the result associated with the first matching value.
When should simple CASE be used?
It is useful when one expression needs to be compared against a known list of values.