Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "+=" mean in T-SQL

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

SET @myvariable += 'test'
like image 577
Lloyd Banks Avatar asked Aug 16 '12 16:08

Lloyd Banks


People also ask

What does \t mean in SQL?

T-SQL (Transact-SQL) is a set of programming extensions from Sybase and Microsoft that add several features to the Structured Query Language (SQL), including transaction control, exception and error handling, row processing and declared variables.

What does LIKE '%' mean in SQL?

The LIKE operator is used in a WHERE clause to search for a specified pattern in a column. There are two wildcards often used in conjunction with the LIKE operator: The percent sign (%) represents zero, one, or multiple characters. The underscore sign (_) represents one, single character.

What does @@ mean in SQL Server?

In SQL Server, symbol @@ is prefixed to global variables. The server maintains all the global variables.

Is != And <> the same in SQL?

If != and <> both are the same, which one should be used in SQL queries? Here is the answer – You can use either != or <> both in your queries as both technically same but I prefer to use <> as that is SQL-92 standard.


2 Answers

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'
like image 111
Guffa Avatar answered Oct 14 '22 18:10

Guffa


+= (Addition Assignment) : Adds two numbers and sets a 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)

+= (String Concatenation Assignment) : Concatenates two strings and sets the string to the result of the operation. For example, if a variable @x equals 'Adventure', then @x += 'Works' takes the original value of @x, adds 'Works' to the string, and sets @x to that new value 'AdventureWorks'.

like image 31
Zeynep Topçu Avatar answered Oct 14 '22 18:10

Zeynep Topçu