What does "+=" mean in T-SQL

The same as many other programming languages - append (or add depending on the variable's datatype, but append in this case) to the existing value.

E.g. if the value of @myvariable is currently hello, after this assignment the value will be hellotest.

It's a shortcut for: SET @myvariable = @myvariable + 'test', introduced in SQL Server 2008.


@myvariable acumulate 'test' for example if @myvariable has a value before like 'hello ' @myvariable += 'test' change the value to 'hello test'


In SQL Server 2008 and later, it is shorthand for addition / concatenation and assignment.

set @x += 'test'

is the same as:

set @x = @x + 'test'

SET @v1 += 'expression' is equivalent to SET @v1 = @v1 + 'expression'.

The += operator cannot be used without a variable. For example, the following code will cause an error:

SELECT 'Adventure' += 'Works'

The following example concatenates using the += operator.

DECLARE @v1 varchar(40);
SET @v1 = 'This is the original.';
SET @v1 += ' More text.';
PRINT @v1;

Here is the result set: This is the original. More text.