SQL server concatenate

DECLARE @test TABLE (
FirstName varchar(50)
)
--
INSERT INTO @test
SELECT 'Jon'
UNION SELECT 'Tom'
UNION SELECT 'Mike'
--
SELECT STUFF((
SELECT DISTINCT ', ' + FirstName
FROM @test
FOR XML PATH('')
), 1, 2, '')
FOR XML does the concat, STUFF removes the first 2 characters from position 1 - i.e. the initial unwanted  ', '

Comments

Popular posts from this blog

Parse XML to dynamic object in C#

C# Updating GUI from different thread