

The above query returns the “Price Range” as a text comment based on the price range for a product: Now, instead of doing SQL case statement followed by a column name we just do Case, When, and then column name with the output range and what we want to print out. The following query is based on the price range for a product: There’s also a searched expression version of it that allow us to work on a range. That’s one use of the SQL Case statement (equality version of it). This means that you’d have seen the “Unknown” output as well if the character was anything else than stated in the When clause. It’s not seen in this example because all the fields match arguments but the Case statement in SQL supports an optional Else argument. So, if we now execute our query with this SQL Case statement it will fetch that information and output it appropriately: Another way to do aliases is to put the name of the alias first followed by equals SQL Case on “MaritalStatus” as in the example above. Furthermore, we’re aliasing the name of the column as “GenderDescription”. Also, if it’s neither of those it’s going to output “Unknown”. In this particular case, whenever “Gender” equals “F” then it’s going to output “Female” and when it equals “M” then it’s going to output “Male”. What it basically means is that we can do Case followed by the field name and then we can have all case expressions.

This is a great equality expression case statement in SQL.
