The case expression gives us the ability to convert column data referenced on a SQL select statement to more meaningful values.
For example, we might wish to convert location IDs in the
Departments table to actual city names. Of course, we could join the
Departments table to the
Locations table but why
incur the overhead of a join if we can simply provide the city name on the original select? If the mapping of location ID to city name changed quite a bit then a join would be
indicated. Otherwise, we should check out the case expression.
To learn how to use the case expression, follow these steps:
location_idand translates it to the appropriate city name. I use an alias (
City) to give the column a meaningful heading on the report.