Sometimes we need to create a CSV list of items, containing in a single row the different values of a column in a table.
This script just accomplish that, in the simplest manner possible:
DECLARE @theListOfValues VARCHAR(MAX)SELECT @theListOfValues = COALESCE(@theListOfValues+',' , '') + MyColumnFROM MyTableSELECT @theListOfValues
How to remove multiple whitespaces from a string with SQL Server 2005
Which performs better: ISNULL or COALESCE
How to remove leading zeros from the results of an SQL Query
Simple way to count characters and words using T-SQL
Domain registration and one full year of Web hosting for Free!
The opinions expressed herein are my own personal opinions and do not represent
my employer's view in any way.