T-SQL SIGN() Function
The T-SQL (Transact-SQL) SIGN() function returns a value indicating the sign of the specified number. It returns the following:
- Returns -1, if the number is less than 0.
- Returns 0, if the number is equal to 0.
- Returns 1, if the number is greater than 0.
Syntax
SIGN(number)
Parameters
number |
Required. Specify the number to test for its sign. |
Return Value
Returns a value indicating the sign of the given number.
Example 1:
The example below shows the usage of SIGN() function.
SELECT SIGN(25); Result: 1 SELECT SIGN(-25); Result: -1 SELECT SIGN(0); Result: 0
Example 2:
Consider a database table called Sample with the following records:
Data | x |
---|---|
Data 1 | 10 |
Data 2 | 14 |
Data 3 | -34 |
Data 4 | 0 |
Data 5 | -67 |
The statement given below can be used to get the sign of values of column x.
SELECT *, SIGN(x) AS SIGN_Value FROM Sample;
This will produce the result as shown below:
Data | x | SIGN_Value |
---|---|---|
Data 1 | 10 | 1 |
Data 2 | 14 | 1 |
Data 3 | -34 | -1 |
Data 4 | 0 | 0 |
Data 5 | -67 | -1 |
❮ T-SQL Functions