Logo 
Search:

SQL Server Articles

Submit Article
Home » Articles » SQL Server » Operator RSS Feeds

Unary Operators : + (positive) , - (negative) , ~ (bitwise not))

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

This article explains different unary operators available in sql server with examples.

Unary operators perform an operation on only one expression of numeric data type.

 

Operator

Meaning

+  (Positive)

Numeric value is positive.

-  (Negative)

Numeric value is negative.

~ (Bitwise NOT)

Returns the ones complement of the number.

 

+ (positive) and - (negative) operators can be used with any expression of numberic datatype. ~ (bitwise not) operator can only be used with any expression of integer datatype.

 


Examples of Unary Operators :

 

Examples of using + (positive) unary operator in SELECT clause :

Example 1 : Using + (positive) unary operator in SELECT clause

SELECT +20

Output

20


Above quey returns postive value only.


Example 2 : Using + (positive) unary operator for table fields in SELECT clause 

SELECT +UnitPrice

FROM   Products

 

Output

UnitPrice

18.00

19.00

10.00

22.00

21.35

  

 

Examples of using - (negative) unary operator in SELECT clause :

Example 1 : Using - (negative) unary operator in SELECT clause

SELECT -20

 

Output

-20

 

Above quey returns negative value only.

 


Example 2 : Using - (negative) unary operator for table fields in SELECT clause

SELECT -UnitPrice

FROM   Products

 

Output

UnitPrice

-18.00

-19.00

-10.00

-22.00

-21.35

  
Share: 



Sarita Patel
Sarita Patel author of Unary Operators : + (positive) , - (negative) , ~ (bitwise not)) is from United States.
 
View All Articles

 
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!