Quantcast
Viewing latest article 5
Browse Latest Browse All 13

Quickie – Concatenate Rows as a String

Image may be NSFW.
Clik here to view.

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


Viewing latest article 5
Browse Latest Browse All 13

Trending Articles