Looking for sql Answers? Try Ask4KnowledgeBase
Looking for sql Keywords? Try Ask4Keywords

SQL Searched CASE in SELECT (Matches a boolean expression)


Example

The searched CASE returns results when a boolean expression is TRUE.

(This differs from the simple case, which can only check for equivalency with an input.)

SELECT Id, ItemId, Price,
  CASE WHEN Price < 10 THEN 'CHEAP'
       WHEN Price < 20 THEN 'AFFORDABLE'
       ELSE 'EXPENSIVE'
  END AS PriceRating
FROM ItemSales
IdItemIdPricePriceRating
110034.5EXPENSIVE
21452.3CHEAP
310034.5EXPENSIVE
410034.5EXPENSIVE
514510AFFORDABLE