If Cells.Type
is not equal to UOM
, you're guaranteed that the result will be 0.
What you are not guaranteed (certainly in SQL Server) is that any expressions in the other branches will not be computed.
So, if you did the following:
CASE WHEN a = 0 THEN 0 ELSE 10/a END
You might get a division by zero error.
And, even in your example:
WHEN Cells.Type = 'UOM' AND Template_Colors.Uom_Case = 'ONE' THEN ...
There is no guarantee on the order in which predicates are evaluated, so Template_Colors.Uom_Case
may still be accessed. Not sure what your concern is around whether this column is accessed or not, so no further advice to offer at the present moment.
Evaluates, in the order specified, Boolean_expression for each
WHEN
clause.Returns result_expression of the first Boolean_expression that evaluates to
TRUE
.If no Boolean_expression evaluates to
TRUE
, the Database Engine returns the else_result_expression if anELSE
clause is specified, or aNULL
value if noELSE
clause is specified.
In a searched
CASE
expression, Oracle searches from left to right until it finds an occurrence of condition that is true, and then returns return_expr. If no condition is found to be true, and anELSE
clause exists, Oracle returns else_expr. Otherwise, Oracle returnsnull
.
If the result is true then the value of the
CASE
expression is the result that follows the condition. If the result is false any subsequentWHEN
clauses are searched in the same manner.
If the
<search condition>
of some<searched when clause>
in a<case specification>
is true, then the value of the<case specification>
is the value of the<result>
of the first (leftmost)<searched when clause>
whose<search condition>
is true, cast as the data type of the<case specification>
.