SQL 2008 now supports compound operators, which is available in other databases since long time
x += 2
is equivalent to x = x+2
Below are the compound operators which are supported by sql server
+=
-=
*=
/=
%=
&=
^=
|=
We can also assign values while declaring variable.
DECLARE @x INT
SET @x = 135
which can be rewritten as
DECLARE @x1 INT = 135
lets see an example
DECLARE @x1 INT
SET @x1 = 135
SET @x1 = @x1 + 2
SELECT @x1
which can be rewritten as
DECLARE @x1 int = 135;
SET @x1 += 2
SELECT @x1
x += 2
is equivalent to x = x+2
Below are the compound operators which are supported by sql server
+=
-=
*=
/=
%=
&=
^=
|=
We can also assign values while declaring variable.
DECLARE @x INT
SET @x = 135
which can be rewritten as
DECLARE @x1 INT = 135
lets see an example
DECLARE @x1 INT
SET @x1 = 135
SET @x1 = @x1 + 2
SELECT @x1
which can be rewritten as
DECLARE @x1 int = 135;
SET @x1 += 2
SELECT @x1
No comments:
Post a Comment