SQL: Building a comma separated list from a select clause
SELECT [Name]
FROM Continent
with just a variable declaration and a use of COALESCE and hey presto, we get our required result of Africa, Antarctica, Asia, Australia and Oceania, Europe, North America, South AmericaThe code is now:
DECLARE @List VARCHAR(1000)SELECT @List = COALESCE(@List + ', ', '') + Name
FROM ContinentSELECT @ListNice and simple. I like!