Case Statement
The CASE statement goes through conditions and returns a value when the first condition is TRUE (similar to IF-THEN-ELSE statement).
Case statement can be used in select queries along with Where, Order By and Group By clause. It can also be used in the Insert statement.
SQL CASE Syntax:
CASE
WHEN condition1 THEN result1
WHEN condition2 THEN result2
WHEN conditionN THEN resultN
ELSE result
END
Example:
Lets use the “Products” table to shorten the name of the “SupplierName” for suppliers named “TechOne” and “TechThree”.
Results:
TechOne and TechThree are changed to a shorter name and TechTwo retains its original format.
SQL Tutorial