在T-SQL中“+ =”是什么意思

时间:2022-10-10 22:31:51

What does the following variable assignment mean in T-SQL?

以下变量赋值在T-SQL中意味着什么?

SET @myvariable += 'test'

7 个解决方案

#1


3  

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

在SQL Server 2008及更高版本中,它是添加/连接和分配的简写。

set @x += 'test'

is the same as:

是相同的:

set @x = @x + 'test'

#2


13  

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.

例如。如果@myvariable的值当前是hello,则在此赋值之后,该值将是hellotest。

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

它是SQL Server 2008中引入的SET @myvariable = @myvariable +'test'的快捷方式。

#3


3  

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

@myvariable例如,如果@myvariable之前的值为'hello'@myvariable + ='test',则将值更改为'hello test'

#4


2  

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

SET @ v1 + ='expression'等同于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.

这是结果集:这是原始的。更多文字。

#5


1  

it is equal to

它等于

SET @myvariable = @myvariable + 'test'

#6


1  

It's shorthand for Something = Something + SomethingElse.

这是Something = Something + SomethingElse的简写。

#7


0  

It appends the value on the right side of += to the variable . In this example @myvariable will be appended with string value test (assuming string @myvariable can accept string values.

它将+ =右侧的值附加到变量。在这个例子中,@ myvariable将附加字符串值测试(假设字符串@myvariable可以接受字符串值。

This logic will also applies to most programming languages

该逻辑也适用于大多数编程语言

#1


3  

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

在SQL Server 2008及更高版本中,它是添加/连接和分配的简写。

set @x += 'test'

is the same as:

是相同的:

set @x = @x + 'test'

#2


13  

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.

例如。如果@myvariable的值当前是hello,则在此赋值之后,该值将是hellotest。

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

它是SQL Server 2008中引入的SET @myvariable = @myvariable +'test'的快捷方式。

#3


3  

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

@myvariable例如,如果@myvariable之前的值为'hello'@myvariable + ='test',则将值更改为'hello test'

#4


2  

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

SET @ v1 + ='expression'等同于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.

这是结果集:这是原始的。更多文字。

#5


1  

it is equal to

它等于

SET @myvariable = @myvariable + 'test'

#6


1  

It's shorthand for Something = Something + SomethingElse.

这是Something = Something + SomethingElse的简写。

#7


0  

It appends the value on the right side of += to the variable . In this example @myvariable will be appended with string value test (assuming string @myvariable can accept string values.

它将+ =右侧的值附加到变量。在这个例子中,@ myvariable将附加字符串值测试(假设字符串@myvariable可以接受字符串值。

This logic will also applies to most programming languages

该逻辑也适用于大多数编程语言