CASE
The standard SQL CASE
expression has two forms:
The simple form searches each value
expression from left to right until it finds one that equals the given expression
and then returns the matching result
.
The searched form evaluates each Boolean condition
from left to right until one is true and returns the matching result
.
CASE ... WHEN
CASE ... WHEN
Syntax
Returns
The result
for the first value
found that matches the expression
is returned.
If no match is found, the result
from the ELSE
clause is returned if it exists; otherwise null
is returned.
Examples
SQL
Query result
ordertype | is_shipped |
---|---|
SHIPPING | true |
shipping | true |
pickup | false |
CASE WHEN ...
CASE WHEN ...
Syntax
Returns
The result
corresponding to the first true condition
is returned.
If no conditions are true, the result
from the ELSE
clause is returned if it exists; otherwise null
is returned.
Examples
SQL
Query result
customer_email | email_domain |
---|---|
Melissa.Whitej@comcast.net |
|
Patricia.Johnsonfp@hotmail.co.uk |
|
Amanda.Thompsonam@gmail.com | gmail |
Last updated