Syntax of CASE in SQL-
CASE
WHEN <condition1> THEN <result1>…….
WHEN <conditionN> THEN <resultN>
ELSE <result>
END;
Example of CASE in SQL-It will returns a value when the first condition is met-
SELECT OrderID, Quantity,
CASE
WHEN Quantity > 20 THEN ‘Quantity is greater than 20’
WHEN Quantity >=20 THEN ‘Quantity is equak to 20’
ELSE ‘Quantity is less than 20’
END
AS QuantityDetails
FROM Order Derails;