-1

My table looks something like this (with 7500 rows):

UserName     Company
Eduard       Google
Alex         Google
Mark         Google
Silvia       Microsoft

Any I need it to look like this:

UserName             Company
Eduard, Alex, Mark   Google
Silvia               Microsoft

Any Idea how to achieve this? I am using SQL Server 2017.

1 Answer 1

1

In SQL Server 2017 you can use STRING_AGG:

SELECT STRING_AGG(UserName,', ') AS UserNames, Company
FROM @t
GROUP BY Company

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.