1.1

Table Of Contents
CASE expression syntax
You can place a CASE expression anywhere an expression is allowed. It chooses an expression to evaluate based
on a boolean test.
CASE
WHEN booleanExpression THEN thenExpression
[ WHEN booleanExpression THEN thenExpression ]...
ELSE elseExpression
END
ThenExpression and elseExpression are both expressions that must be type-compatible. For built-in types, this
means that the types must be the same or a built-in broadening conversion must exist between the types.
Example
-- returns 3
VALUES CASE WHEN 1=1 THEN 3 ELSE 4 END
-- returns 7
VALUES
CASE
WHEN 1 = 2 THEN 3
WHEN 4 = 5 THEN 6
ELSE 7
END
CAST function
The CAST function converts a value from one data type to another and provides a data type to a dynamic
parameter (?) or a NULL value.
CAST expressions are permitted anywhere expressions are permitted.
Syntax
CAST ( [ Expression | NULL | ? ]
AS Datatype)
The data type to which you are casting an expression is the target type. The data type of the expression from
which you are casting is the source type.
CAST conversions among SQL-92 data types
The following table shows valid explicit conversions between source types and target types for SQL data types.
This table shows which explicit conversions between data types are valid. The rst column on the table lists the
source data types. The rst row lists the target data types. A "Y" indicates that a conversion from the source to
the target is valid. For example, the rst cell in the second row lists the source data type SMALLINT. The
remaining cells on the second row indicate the whether or not you can convert SMALLINT to the target data
types that are listed in the rst row of the table.
543
SQL Language Reference