Considerations For Case; Data Type Of The Case Expression; Character Data Type; Numeric Data Type - HP Neoview SQL Reference Manual

Hide thumbs Also See for Neoview SQL:
Table of Contents

Advertisement

CASE expression returns the value expression specified in the ELSE clause, or NULL if the
ELSE value is not specified.

Considerations for CASE

Data Type of the CASE Expression

The data type of the result of the CASE expression depends on the data types of the result
expressions. If the results all have the same data type, the CASE expression adopts that data
type. If the results have comparable but not identical data types, the CASE expression adopts
the data type of the union of the result expressions. This result data type is determined in these
ways.

Character Data Type

If any data type of the result expressions is variable-length character string, the result data type
is variable-length character string with maximum length equal to the maximum length of the
result expressions.
Otherwise, if none of the data types is variable-length character string, the result data type is
fixed-length character string with length equal to the maximum of the lengths of the result
expressions.

Numeric Data Type

If all of the data types of the result expressions are exact numeric, the result data type is exact
numeric with precision and scale equal to the maximum of the precisions and scales of the result
expressions.
For example, if result-expression-1 and result-expression-2 have data type
NUMERIC(5) and result-expression-3 has data type NUMERIC(8,5), the result data type
is NUMERIC(10,5).
If any data type of the result expressions is approximate numeric, the result data type is
approximate numeric with precision equal to the maximum of the precisions of the result
expressions.

Datetime Data Type

If the data type of the result expressions is datetime, the result data type is the same datetime
data type.

Interval Data Type

If the data type of the result expressions is interval, the result data type is the same interval data
type (either year-month or day-time) with the start field being the most significant of the start
fields of the result expressions and the end field being the least significant of the end fields of
the result expressions.

Examples of CASE

Use a simple CASE to decode JOBCODE and return NULL if JOBCODE does not match any
of the listed values:
SELECT last_name, first_name,
CASE jobcode
WHEN 100 THEN 'MANAGER'
WHEN 200 THEN 'PRODUCTION SUPV'
WHEN 250 THEN 'ASSEMBLER'
WHEN 300 THEN 'SALESREP'
WHEN 400 THEN 'SYSTEM ANALYST'
WHEN 420 THEN 'ENGINEER'
WHEN 450 THEN 'PROGRAMMER'
296
SQL Functions and Expressions

Advertisement

Table of Contents
loading

Table of Contents