The CASE expression is evaluated by a value, that is, it is used to evaluate one of the result set based on some condition.
Example:
SELECT CASE WHEN type = 1 THEN 'foo' WHEN type = 2 THEN 'bar' ELSE 'baz' END AS name_for_numeric_type FROM sometable`
The CASE statement executes one of many statements based on some condition.
Example:
CASE WHEN action = 'update' THEN UPDATE sometable SET column = value WHERE condition; WHEN action = 'create' THEN INSERT INTO sometable (column) VALUES (value); END CASE
You see how similar they are, but the operator does not evaluate the value and can be used on its own, while the expression should be part of the expression, for example. request or task. You cannot use an operator in a query, since the query cannot contain operators, but only expressions that must evaluate something (the query itself is an expression in a sense), for example. SELECT CASE WHEN condition THEN UPDATE table SET something; END CASE SELECT CASE WHEN condition THEN UPDATE table SET something; END CASE does not make sense.
lanzz Sep 15 '12 at 11:15 2012-09-15 11:15
source share