SIGN (SQL)
Synopsis
SIGN(numeric-expression)
{fn SIGN(numeric-expression)}
Description
SIGN returns the following:
-
-1 if numeric-expression is less than zero.
-
0 (zero) if numeric-expression is zero: 0, +0, or -0.
-
1 if numeric-expression is greater than zero.
-
NULL if numeric-expression is NULL, or if it is a non-numeric string.
SIGN can be used as either an ODBC scalar function (with the curly brace syntax) or as an SQL general function.
SIGN converts numeric-expression to canonical form before determining its value. For example, SIGN(-+-+3) and SIGN(-3+5) both return 1, indicating a positive number.
In InterSystems SQL, two negative signs (hyphens) are the in-line comment indicator. For this reason, a SIGN argument specifying two successive negative signs must be presented as a numeric string enclosed in quotes.
Arguments
numeric-expression
A number for which the sign is to be returned.
Examples
The following examples shows the effects of SIGN:
SELECT SIGN(-49) AS PosNeg
returns -1.
SELECT {fn SIGN(-0.0)} AS PosNeg
returns 0.
SELECT SIGN(-+-16.748) AS PosNeg
returns 1.
SELECT {fn SIGN(NULL)} AS PosNeg
returns <null>.
See Also
-
+ (Positive) and – (Negative) unary operators
-
ABS function
-
ISNUMERIC function