SIGN() Function in SQL Server
SIGN() function :
This function in SQL Server is used to return the sign of the specified number. It returns 1 if the number is positive, -1 if the number is negative and 0 for zero number.
Features :
- This function is used to find the sign of the given number i.e., that given number is positive or negative or zero.
- This function accepts only all type of numbers i.e., positive, negative, zero.
- This function also accepts fraction numbers.
- This function always returns 1 if the number is positive, -1 if the number is negative and 0 for zero number.
Syntax :
SIGN(number)
Parameter :
This method accepts a parameter as given below :
- number : Specified number to return the sign for.
Returns :
It returns the sign of the specified number.
Example-1 :
Getting the result as 1 i.e., positive for the specified number 2.
SELECT SIGN(2);
Output :
1
Example-2 :
Getting the result as -1 i.e., negative for the specified number -7.
SELECT SIGN(-7);
Output :
-1
Example-3 :
Using SIGN() function with a variable and getting the result as 0 for the specified number 0.
DECLARE @Parameter_Value INT; SET @Parameter_Value = 0; SELECT SIGN(@Parameter_Value);
Output :
0
Example-4 :
Getting the result as 1 i.e., positive for the result of “5/2”.
SELECT SIGN(5/2);
Output :
1
Example-5 :
Using SIGN() function with a variable and getting the result as 1 i.e., positive for the float value “5.75”.
DECLARE @Parameter_Value FLOAT; SET @Parameter_Value = 5.75; SELECT SIGN(@Parameter_Value);
Output :
1.0
Application :
This function is used to return the sign of the specified number.
Contact Us