Logo 
Search:

SQL Server Articles

Submit Article
Home » Articles » SQL Server » Math FunctionsRSS Feeds

SIGN Function

Posted By: Sarita Patel     Category: SQL Server     Views: 5304

This article explains SIGN function of sql server with examples.

SIGN is used to get sign of specified number. It returns either positive i.e. +1, negative i.e. -1 or zero i.e. 0 . 


Syntax of SIGN Function :

SIGN (numeric_expression)

numeric_expression is a numeric or approximate numeric data type except for bit. 

Return type of SIGN is float.



Examples of SIGN Function :

Example 1 : Use of SIGN function in select clause

SELECT SIGN(-20) 

Output
-1

Above example returns sign of specified number with digit 1.



Example 2 : Use of SIGN function to display field value of table in a select clause

SELECT ProductName, SIGN(UnitPrice) AS Sign
FROM   Invoices

Output
ContactName                  Sign
Maria Anders                  1.00
Ana Trujillo                     1.00 
Antonio Moreno              1.00
Thomas Hardy                1.00
Christina Berglund           1.00
Hanna Moos                    1.00

Above example displays sign of UnitPrice field of invoices table.



Example 3 : Use of SIGN function in where clause

SELECT ProductName, UnitPrice
FROM   Invoices
WHERE  SIGN(UnitPrice) = '-1'

Above example returns all products having negative unitprice from invoices table. 
  
Share: 

 
 
 

Didn't find what you were looking for? Find more on SIGN Function Or get search suggestion and latest updates.

Sarita Patel
Sarita Patel author of SIGN Function is from United States.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!