SQL SERVER – 2008 – Compound Assignment Operators

SQL SERVER 2008 has introduced new concept of Compound Assignment Operators. Compound Assignment Operators are available in many other programming languages for quite some time. Compound Assignment Operators is operator where variables are operated upon and assigned on the same line.

Let us see following operation without using Compound Assignment Operators.
DECLARE @myVar INT
SET
@myVar = 10
SET @myVar = @myVar * 5
SELECT @myVar AS MyResult
GO

Above operation can be done using Compound Assignment Operators as demonstrated in following script.
DECLARE @myVar INT
SET
@myVar = 10
SET @myVar *= 5
SELECT @myVar AS MyResult
GO

Reference : Pinal Dave (http://blog.SQLAuthority.com)

About these ads

One thought on “SQL SERVER – 2008 – Compound Assignment Operators

  1. Pingback: SQL SERVER – Weekly Series – Memory Lane – #032 | Journey to SQL Authority with Pinal Dave

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s