SQL SIGN Function

The SQL SIGN function is one of the Mathematical functions, which is used to return the sign of the specified expression, and the sign may be Positive (+1), Negative (-1), or Zero (0).

Syntax

The basic syntax of the SQL Server SIGN Function is as shown below:

SELECT SIGN (Numeric_Expression)
FROM [Source]

Numeric_Expression: This function accepts exact numeric or approximately numeric data types. Remember that it will not take the Bit data type.

  • If the Numeric_Expression argument is positive or negative zero, the SIGN function will return Zero as a result.
  • If the Numeric_Expression argument is a Negative Number, the SIGN function will return Negative One(-1) as a result.
  • And if it is a positive Number, the SIGN function returns Positive One(+1) as a result.

SQL SIGN Function Example

In this example, We are going to find the sign values of different data (positive and negative values) and display the output.

We are finding the Sign of @i. We used the ALIAS Column to assign a new name to the SQL Server result as ‘Sign Result 1’.

For the below statements 2 and 3, We used the SIGN Mathematical function directly on the positive values.

Next twoResult4 and 5, we used positive and negative zero.

And for the 6 and 7, we directly used on the negative values.

DECLARE @i INT
SET @i = 10

SELECT SIGN(@i)AS [Sign Result 1]

-- Finding Degrees directly
SELECT SIGN(150) AS [Sign Result 2]
SELECT SIGN(14.25) AS [Sign Result 3]

SELECT SIGN(0) AS [Sign Result 4]
SELECT SIGN(-0) AS [Sign Result 5]

SELECT SIGN(-25) AS [Sign Result 6]
SELECT SIGN(-104.449) AS [Sign Result 7]
SIGN Example 1

Example 2

In this SQL Server SIGN Function example, We are going to find the sign of all the records present in the [Service Grade] column using the DEGREES Function. Original table = Math Table data

SELECT [EnglishProductName]
      ,[Color]
      ,[StandardCost]
      ,[SalesAmount]
      ,[TaxAmt]
      ,[Service Grade]
      ,SIGN([Service Grade]) AS [Service_Sign]
  FROM [Mathemetical Functions]
SQL SIGN Function 2