SMALLINT
The SMALLINT function returns a small integer representation either of a number or of a string representation of a number.
Numeric to Smallint:
>>-SMALLINT(numeric-expression)--------------------------------><
String to Smallint:
>>-SMALLINT(string-expression)---------------------------------><
The schema is SYSIBM.
Numeric to Smallint
- numeric-expression
- An expression that returns a value of any built-in numeric data
type.
The result is the same number that would occur if the argument were assigned to a small integer column or variable. If the whole part of the argument is not within the range of small integers, an error occurs. If present, the decimal part of the argument is truncated.
String to Smallint
- string-expression
- An expression that returns a value of character
or graphic string (except a CLOB or DBCLOB) with a length attribute
that is not greater than 255 bytes for a character string or 127 for
a graphic string. The string must contain a valid string representation
of a number.
The result is the same number that would result from CAST(string-expression AS SMALLINT). Leading and trailing blanks are eliminated and the resulting string must conform to the rules for forming an SQL integer constant. The fractional part of the argument is truncated.
The result of the function is a small integer.
The result can be null; if the argument is null, the result is the null value.
SELECT SMALLINT(AVG(EDLEVEL)+.5)
FROM DSN8A10.EMP
WHERE DEPT = 'A00';
Assuming that the five employees
in the department have education levels of '19', '18', '14', '18',
and '14', the result is '17'.