Unary Operators

I am going to stick to writing my series of very short articles or tidbits on Transaction SQL Operators. An operator is a symbol specifying an action that is performed on one or more expressions.

I will exploring the Unary Operators today. In mathematics, a unary operation is an operation with only one operand.

Microsoft Transaction SQL has three unary operators: positive, negative, and bitwise not.

I have personally used the bitwise operators when dealing with data from car manufacturing devices that use application specific integrated circuits (ASIC). Since the memory space of these little devices are small, bits are used to store information about a condition.

The example script below explores all three operators.

The output of the above TSQL statements is listed below.

I find the positive unary operator kinda-of useless. It will not take a negative number and make it positive. By default, a non-negative number is positive. I think is part of the language for mathematical completeness.

To complete my exploration of operators, I will be talking about operator precedence next time.

Related posts

Leave a Comment