T-SQL – Query to get Distinct,Sorted, Comma Separated values in to a variable
CREATE TABLE #temp(name char(3))
INSERT INTO #temp VALUES ('CD')
,('AB')
,('LM')
,('BC')
,('GH')
,('KJ')
,('AB')
DECLARE @cols AS NVARCHAR(MAX);
SELECT @COLS = substring(list, 1, len(list) - 1)
FROM (SELECT list =
(SELECT DISTINCT...
2015-02-10 (first published: 2015-02-02)
10,416 reads