CONCAT (TSQL Function)

Returns the concatenation of two or more strings, replacing NULL values by empty strings.

Syntax

CONCAT ( string_value1 , string_value2 [, ...string_valueN] )

Arguments

string_value
is a string to concatenate with the others. It is of type varchar.

Return Types

Returns varchar.

The collation of the returned string is the combination of the collations of all arguments. An error is raised if collations are not compatible.

Remarks

CONCAT takes all string arguments and concatenates them.

At least two strings must be passed; else, an error is raised.

NULL values are replaced by empty strings.

Examples

PRINT CONCAT('Mozart was born on ', 27, ' January ', 1756);

The result is:

Mozart was born on 27 January 1756

Another example:

PRINT CONCAT(10, 20, 30, 'Hello', NULL, 'World');

The result is:

102030HelloWorld

Incompatible collations:

PRINT CONCAT('asdf' COLLATE en_cs_as, 'asdf' COLLATE en_ci_ai)

The result is:

<Syntax error. Cannot resolve conflict between en_ci_ai and en_cs_as collations.>
RSQL, a simple alternative to Microsoft SQL Server