Skip to content
Advertisement

Concat rows for employee roles

I’m using SQL Server. Looking for similar functionality as GROUP_CONCAT or listagg functions provided in other Databases. Seems like STUFF function is provided to concat rows. Here’s my attempt.

Employee

Role

EmployeeRole

Expected Output

Advertisement

Answer

In SQLServer 2017, you can use aggregate function STRING_AGG():

Note: table aliases make the query more concise and easier to read. I modified the query to use them.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement