Assignment Operators in TSQL 2008

TSQL has improved its assignment Operators in the C language convention.

In SQL SERVER 2000 or SQL SERVER 2005 the assignment operators are written as

Declare @i int

Declare @s varchar(100)

set @i = 10

set @s = ‘WORD’

set @i = @i  * 40

set @s = @s + ‘PRESS’

In SQL SERVER 2008

Declare @i int = 10

Declare @s varchar(100) = ‘WORD’

set @i *=  40

set @s += ‘PRESS’

select @i,@s

In the sameway the other operators that can be used are

-= Subtraction

/= Division

%= Modulo

^= Bitwise exclusive OR

|= Bitwise OR

&= Bitwise AND

Leave a Reply