T-SQL Tutorial T-SQL Advanced Database Management T-SQL References

T-SQL + operator



The T-SQL (Transact-SQL) + operator can be used to concatenate two or more strings together.

Syntax

string1 + string2 [ + string_n ]

Parameters

string1 Required. Specify the first string to concatenate.
string2 Required. Specify the second string to concatenate.
string_n Optional. Specify the nth string to concatenate.

Return Value

Returns the concatenated string.

Example 1:

The example below shows how to use + operator to concatenate two or more string values.

SELECT 'Alpha' + 'Coding' + 'Skills';
Result: 'AlphaCodingSkills'

SELECT '10' + '20' + '30';
Result: '102030'

SELECT '10' + 20 + '30';
Result: '102030'

SELECT '10' + 20 + 30;
Result: '102030'

SELECT 'a' + 'b' + 'c' + 'd';
Result: 'abcd'

Example 2:

Two additional single quotes within the surrounding single quotation can be used to concatenate single quotes. See the example below:

SELECT 'Let' + '''' + 's learn T-SQL';
Result: Let's learn T-SQL

Example 3:

Consider a database table called Employee with the following records:

EmpIDFirstNameLastName
1JohnSmith
2MarryKnight
3JoWilliams
4KimFischer
5RameshGupta
6HuangZhang

In the query below, the + operator is used to concatenate records of column FirstName and column LastName.

SELECT *, FirstName + ' ' + LastName AS FullName FROM Employee;

This will produce the result as shown below:

EmpIDFirstNameLastNameFullName
1JohnSmithJohn Smith
2MarryKnightMarry Knight
3JoWilliamsJo Williams
4KimFischerKim Fischer
5RameshGuptaRamesh Gupta
6HuangZhangHuang Zhang

❮ T-SQL Functions