Quickie – Concatenate Rows as a String

Today I needed to concatenate a field from multiple rows in SQL Server to get a list of people names. Instead of doing it in code, you can use the following syntax:

DECLARE @Names VARCHAR(8000)
SELECT @name = ”
SELECT @Names = @Names + ‘,’ + Names FROM People
SELECT SUBSTRING(2, @Names, 7998)

Happy Concatenating!!

Reference

Hello, nice to meet you

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Leave a Reply