Table of Contents

Column to CSV

The first (intuitive approach)

SELECT @s = isnull(@s + ', ' + CONVERT (VARCHAR(10),NumericValue), CONVERT (VARCHAR(10),NumericValue))
FROM Measurement
ORDER BY ColumnA;

Second approach

SELECT SUBSTRING(
(SELECT ',' + CONVERT (VARCHAR(10),FloatValue)
FROM Measurement
ORDER BY ColumnA
FOR XML PATH('')),2,200000) AS CSV

Experimental Comparison

-- First approach
SQL Server Execution Times:
   CPU time = 1092 ms,  elapsed time = 1090 ms.
-- Second approach
 SQL Server Execution Times:
   CPU time = 63 ms,  elapsed time = 85 ms.