STRING_AGG

Concatenates the values of string expressions and places separator values between them. The separator is not added at the end of string.

Syntax

STRING_AGG ( expression, separator )

Arguments

expression

Is an expression of any type. Expressions are converted to NVARCHAR or VARCHAR types during concatenation. Non-string types are converted to NVARCHAR type.

separator

Is an expression of NVARCHAR or VARCHAR type that is used as separator for concatenated strings.

Return types

NVARCHAR or VARCHAR.

Example

SELECT STRING_AGG ( ISNULL(FirstName,'N/A'), ',') AS csv
  FROM Person.Person;

See Also