NonStop SQL/MP Reference Manual

Table Of Contents
NonStop SQL/MP Reference Manual142115
C-4
Examples—CASE Expression
Examples—CASE Expression
The following example decodes movie_type and returns NULL if movie_type does
not match any of the listed values:
SELECT movie_name,
CASE movie_type
WHEN 1 THEN "Horror"
WHEN 2 THEN "Comedy"
WHEN 3 THEN "Drama"
ELSE NULL
END
FROM movies;
The following example returns last_name, first_name, and a value based on salary
that depends on the value of employee.dept_num:
SELECT last_name, first_name,
CASE
WHEN dept_num = 9000 THEN salary * 1.10
WHEN dept_num = 1000 THEN salary * 1.12
ELSE salary
END
FROM employee;
CAST Function
CAST is a function that associates a character or numeric data type with a parameter.
parameter
specifies a parameter (and, optionally, an INDICATOR parameter) to associate with
the data type data-type.
The syntax for specifying a parameter is the same as described under Parameters
on
page P-12, including the INDICATOR clause but without the TYPE AS clause.
data-type
specifies a character or numeric data type to associate with parameter.
The syntax for specifying data-type is the same as described under Data Types
on page D-1 except that data-type cannot include the COLLATE clause and
CAST ( parameter AS data-type )