Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

SIGN() Function in SQL Server

  • Last Updated : 30 Dec, 2020

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 :

Attention reader! Don’t stop learning now. Learn SQL for interviews using SQL Course  by GeeksforGeeks.

  • 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.

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!