Quantcast
Channel: Clive Ciappara - Developer for Apps & Websites » Quickie
Viewing all articles
Browse latest Browse all 13

Quickie – Concatenate Rows as a String

$
0
0

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 all articles
Browse latest Browse all 13

Trending Articles