Case Syntax

A case expression can be used to evaluate more than one condition, and return one of many possible results.

Syntax

CASE search-expression
    WHEN expression [, {AND | OR} expression [ ... ]] THEN
      statements
  [ WHEN expression [, {AND | OR} expression [ ... ]] THEN
      statements
    ... ]
  [ ELSE
      statements ]
END;

Example

SELECT 
CASE WHEN customer_id = 5
AND customer_zip = 40230
THEN 2 ELSE 0 END
FROM customers;
  • 27
  • 09-Aug-2015
  • 697 Views