sql server - How to use COALESCE with multiple rows and ...
Basically, check if the variable has been initialized yet. If it hasn't, set it to the empty string, and append the first city (no leading comma). If it has, then append a comma, then append the city. DECLARE @col nvarchar(MAX); SELECT @col = COALESCE(@col + ',', '') + city FROM dbo.tbl WHERE state = 'California';
DA: 62 PA: 89 MOZ Rank: 4