Compound operators execute some operation and set an original value to the result of the operation. For example, if a variable @x equals 35, then @x += 2 takes the original value of @x, add 2 and sets @x to that new value (37).
- Add Equals “+=”
- Subtract Equals “-=”
- Multiply Equals “*=”
- Divide Equals “/=”
- Modulo Equals “%=”
- Bitwise AND Equals “&=”
- Bitwise OR Equals “|=”
- Bitwise Exclusive OR Equals “^=”
Example: DECLARE @v1 INT;
SET @v1 =
10;
SET @v1 +=
2;
select @v1;
Example: DECLARE @v1 INT;
SET @v1 =
10;
SET @v1 -=
2;
select @v1;
Example: DECLARE @v1 INT;
SET @v1 =
10;
SET @v1 *=
2;
select @v1;
Example: DECLARE @v1 INT;
SET @v1 =
10;
SET @v1 /=
2;
select @v1;
Example: DECLARE @v1 INT;
SET @v1 =
15;
SET @v1 %=
2;
select @v1;
Example: DECLARE @v1 INT;
SET @v1 =
10;
SET @v1 &=
2;
select @v1;
Example: DECLARE @v1 INT;
SET @v1 =
10;
SET @v1 |=
2;
select @v1;
Bitwise Exclusive OR Equals (^=): Performs a bitwise exclusive OR and sets the
original value to the result.
Example: DECLARE @v1 INT;
SET @v1 =
10;
SET @v1 ^=
2;
select @v1;
No comments:
Post a Comment