From the course: Querying Microsoft SQL Server 2012
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Using CASE expressions - SQL Server Tutorial
From the course: Querying Microsoft SQL Server 2012
Using CASE expressions
In querying our databases, at times we might find there is a necessity for substituting one value in the database for another value in our output results. SQL server's case statement allows for this substitution and effectively, it takes a value from a field in the database and provides another value for that in the output results. So in its simplest form, CASE is used to translate a value stored in the database to a different value used for display. A good example is a CASE expression used to translate what might be considered cryptic information stored in your database to a more readable term. Sometimes, these cryptic values are stored, because they help to reduce the storage space size in the database but they're not always user friendly when it comes time to view them in the output results. Let's switch over to SQL and see and example of how to use the CASE expression. So here in this instance, we've executed a simple query against our person.person table. And we've returned the…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.