Before SQL Server 2017 came along, there wasn’t a T-SQL equivalent of the MySQL GROUP_CONCAT()
function. This function allows you to return a result set as a comma-separated list, as opposed to listing each row as a separate row (as with a normal result set).
Prior to SQL Server 2017, if you wanted to put your result into a comma separated list, you’d need to find a workaround, perhaps using a combination of STUFF()
and FOR XML PATH()
.
However, T-SQL now has the STRING_AGG()
function which is available from SQL Server 2017. This function does pretty much the same thing as MySQL’s GROUP_CONCAT()
function (with some minor differences).