TechNet
Export (0) Print
Expand All

SIGN (Transact-SQL)

 

THIS TOPIC APPLIES TO: yesSQL Server (starting with 2008)yesAzure SQL DatabaseyesAzure SQL Data Warehouse yesParallel Data Warehouse

Returns the positive (+1), zero (0), or negative (-1) sign of the specified expression.

Topic link icon Transact-SQL Syntax Conventions

-- Syntax for SQL Server, Azure SQL Database, Azure SQL Data Warehouse, Parallel Data Warehouse  
  
SIGN ( numeric_expression )  

numeric_expression
Is an expression of the exact numeric or approximate numeric data type category, except for the bit data type.

Specified expressionReturn type
bigintbigint
int/smallint/tinyintint
money/smallmoneymoney
numeric/decimalnumeric/decimal
Other typesfloat

The following example returns the SIGN values of numbers from -1 to 1.

DECLARE @value real  
SET @value = -1  
WHILE @value < 2  
   BEGIN  
      SELECT SIGN(@value)  
      SET NOCOUNT ON  
      SELECT @value = @value + 1  
      SET NOCOUNT OFF  
   END  
SET NOCOUNT OFF  
GO  

Here is the result set.

(1 row(s) affected)  
  
------------------------   
-1.0                       
  
(1 row(s) affected)  
  
------------------------   
0.0                        
  
(1 row(s) affected)  
  
------------------------   
1.0                        
  
(1 row(s) affected)  

The following example returns the SIGN values of three numbers.

SELECT SIGN(-125), SIGN(0), SIGN(564);  

Here is the result set.

----- ----- -----

-1 0 1

Mathematical Functions (Transact-SQL)

Community Additions

ADD
Show:
© 2016 Microsoft