Part 106: The CASE Expression: Simple vs Searched CASE

Part 106 Technology Updated September 12, 2026

Part 106: The CASE Expression: Simple vs Searched CASE

CASE is SQL's equivalent of if / else or switch statements.


1. Searched CASE (Most Powerful & Flexible)

SELECT 
  product_name,
  stock_quantity,
  CASE 
    WHEN stock_quantity = 0 THEN 'Out of Stock'
    WHEN stock_quantity < 10 THEN 'Critical Low'
    WHEN stock_quantity < 50 THEN 'Moderate'
    ELSE 'Sufficient'
  END AS inventory_health
FROM products;

Key Takeaways

  • Always provide an ELSE clause to prevent unhandled conditions from evaluating to NULL.

In Part 107, we explore Conditional Aggregation with CASE Expressions!