Starting with SQL Server 2017, you can now make your query results appear as a list. This means you can have your result set appear as a comma-separated list, a space-separated list, or whatever separator you choose to use.
While it’s true that you could achieve this same effect prior to SQL Server 2017, it was a bit fiddly.
Transact-SQL now has the STRING_AGG()
function, which concatenates the values of string expressions and places separator values between them. This works in much the same way to MySQL’s GROUP_CONCAT()
function.
This article provides examples that demonstrate the T-SQL STRING_AGG()
function.
Continue reading →