SQL Server SIGN() Function

The SIGN() function in SQL Server determines the sign of a number and returns a value indicating whether the number is positive, negative, or zero. It's a straightforward but useful mathematical function.



SIGN(): Definition and Usage

SIGN() is frequently used in conditional logic or calculations where you need to know the sign of a number without necessarily needing the number's actual value. This is a quick and efficient way to categorize numbers based on their sign.

Return Values

The SIGN() function returns:

  • 1 if the number is positive (greater than 0)
  • 0 if the number is zero
  • -1 if the number is negative (less than 0)

Syntax

Syntax

SIGN(number)
      

Parameter Values

Parameter Description
number The number to check the sign of. This is required and must be a numeric value.

Examples

Sign of a Positive Number

This example shows the sign of a positive number.

Syntax

SELECT SIGN(255.5);
      
Output

1
      

Sign of a Negative Number

This example shows the sign of a negative number.

Syntax

SELECT SIGN(-12);
      
Output

-1