Case (Conditional) Expression - HP Neoview SQL Reference Manual

Hide thumbs Also See for Neoview SQL:
Table of Contents

Advertisement

CASE (Conditional) Expression

"Considerations for CASE"
"Examples of CASE"
The CASE expression is a conditional expression with two forms: simple and searched.
In a simple CASE expression, Neoview SQL compares a value to a sequence of values and sets
the CASE expression to the value associated with the first match—if there is a match. If there is
no match, Neoview SQL returns the value specified in the ELSE clause (which can be null).
In a searched CASE expression, Neoview SQL evaluates a sequence of conditions and sets the
CASE expression to the value associated with the first condition that is true—if there is a true
condition. If there is no true condition, Neoview SQL returns the value specified in the ELSE
clause (which can be null).
Simple CASE is:
CASE case-expression
WHEN expression-1 THEN {result-expression-1 | NULL}
WHEN expression-2 THEN {result-expression-2 | NULL}
...
WHEN expression-n THEN {result-expression-n | NULL}
[ELSE {result-expression | NULL}]
END
Searched CASE is:
CASE
WHEN condition-1 THEN {result-expression-1 | NULL}
WHEN condition-2 THEN {result-expression-2 | NULL}
...
WHEN condition-n THEN {result-expression-n | NULL}
[ELSE {result-expression | NULL}]
END
case-expression
specifies a value expression that is compared to the value expressions in each WHEN clause
of a simple CASE. The data type of each expression in the WHEN clause must be
comparable to the data type of case-expression.
expression-1 ... expression-n
specifies a value associated with each result-expression. If the value of an expression
in a WHEN clause matches the value of case-expression, simple CASE returns the
associated result-expression value. If there is no match, the CASE expression returns
the value expression specified in the ELSE clause, or NULL if the ELSE value is not specified.
result-expression-1 ... result-expression-n
specifies the result value expression associated with each expression in a WHEN clause
of a simple CASE, or with each condition in a WHEN clause of a searched CASE. All of
the result-expressions must have comparable data types, and at least one of the
result-expressions must return nonnull.
result-expression
follows the ELSE keyword and specifies the value returned if none of the expressions in the
WHEN clause of a simple CASE are equal to the case expression, or if none of the conditions
in the WHEN clause of a searched CASE are true. If the ELSE result-expression clause
is not specified, CASE returns NULL. The data type of result-expression must be
comparable to the other results.
condition-1 ... condition-n
specifies conditions to test for in a searched CASE. If a condition is true, the CASE
expression returns the associated result-expression value. If no condition is true, the
354
SQL Functions and Expressions

Advertisement

Table of Contents
loading

Table of Contents