A searched CASE expression evaluates separate Boolean conditions in sequence and returns the result associated with the first condition that is true.
Searched CASE is more flexible than simple CASE because each condition can use different columns, operators, and calculations.
Classify customers based on their total spending.
SELECT
CustomerName,
TotalSpent,
CASE
WHEN TotalSpent >= 100000 THEN 'Platinum'
WHEN TotalSpent >= 50000 THEN 'Gold'
WHEN TotalSpent >= 10000 THEN 'Silver'
ELSE 'Standard'
END AS CustomerSegment
FROM Customers;
Searched CASE is widely used for customer segmentation, risk classification, performance grading, and business-rule implementation.
- Searched CASE evaluates separate conditions.
- Conditions are evaluated in order.
- The first true condition determines the result.
- Different columns can be used in conditions.
- It is useful for complex business rules.
What is searched CASE?
Searched CASE evaluates independent conditions and returns the result for the first condition that evaluates to true.
Why is searched CASE more flexible?
Each WHEN clause can contain a different condition using different columns, operators, or calculations.