Assignment Operator

I am going to continue the 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 Assignment Operator today. This equality symbol = in mathematics.

There are two ways in which the assignment operator can be used: alias – associating a column heading with a expression or storage – placing the results of a expression into a variable.

The TSQL example below compares the assignment operator against old and new ANSI standards for aliasing.

The output of each calculation is listed below.

The TSQL example below is a good example of using the assignment operator to store the results of a expression into a variable. It creates a temporary table, declares a local variable and sums up the numbers in the temporary table.

The output of the summation is listed below.

Next time, I will be exploring the Bitwise Operators.

Related posts

Leave a Comment