SMALLINT
The SMALLINT function returns a small integer representation.
The SMALLINT function returns a small integer representation of
- A number
- A character or graphic string representation of a decimal number
- A character or graphic string representation of an integer
- A character or graphic string representation of a floating-point number
- A character or graphic string representation of a decimal floating-point number
Numeric to Smallint
- numeric-expression
- An expression that returns a numeric 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 is returned. The fractional part of the argument is truncated.
String to Smallint
- string-expression
- An expression that returns a value that is a character-string
or graphic-string representation of a number.
If the argument is a string-expression, 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 a floating-point, decimal floating-point, integer, or decimal constant. If the whole part of the argument is not within the range of small integers, an error is returned. Any fractional part of the argument is truncated.
The result of the function is a small integer. If the argument can be null, the result can be null. If the argument is null, the result is the null value.
Note
Syntax alternatives: The CAST specification should be used to increase the portability of applications. For more information, see CAST specification.
Example
- Using the EMPLOYEE table, select a list containing salary (SALARY)
divided by education level (EDLEVEL). Truncate any decimal in the
calculation. The list should also contain the values used in the calculation
and the employee number (EMPNO).
SELECT SMALLINT(SALARY / EDLEVEL), SALARY, EDLEVEL, EMPNO FROM EMPLOYEE