Home > SQL Queries, SQL Server, T-SQL > Compound Operators in SQL Server 2008

Compound Operators in SQL Server 2008

February 10, 2010 Leave a comment Go to comments

 The compound operators are supported by most of the programming languages available today in the market. However this feature was not available in SQL server 2005 and prior versions of SQL server.  SQL server 2008 supports the use of compound operators. The list of compound operators suppoerted by SQL server 2008 (T-SQL) are as below

Operator Link to more information Action
+= += (Add EQUALS) Adds some amount to the original value and sets the original value to the result.
-= -= (Subtract EQUALS) Subtracts some amount from the original value and sets the original value to the result.
*= *= (Multiply EQUALS) Multiplies by an amount and sets the original value to the result.
/= /= (Divide EQUALS) Divides by an amount and sets the original value to the result.
%= %= (Modulo EQUALS) Divides by an amount and sets the original value to the modulo.
&= &= (Bitwise AND EQUALS) ) Performs a bitwise AND and sets the original value to the result.
^= ^= (Bitwise Exclusive OR EQUALS) Performs a bitwise exclusive OR and sets the original value to the result.
|= |= (Bitwise OR EQUALS) Performs a bitwise OR and sets the original value to the result.

 An example script is provided for your reference


DECLARE @I INT
SET @I = 99
SET @I += 1 -- @I = @I + 1
SET @I /= 2 -- @I = @I / 2
PRINT @I
 
Advertisements
Categories: SQL Queries, SQL Server, T-SQL
  1. No comments yet.
  1. No trackbacks yet.

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

%d bloggers like this: