I am trying to get a unique list of IDs from a table in CSV format. I am close I just need to be able to remove duplicates. So far I have:
DECLARE @csv VARCHAR(max)
set @csv = null
SELECT @csv = COALESCE(@csv + ',', '') + ''''+ID+''''
FROM TABLE
select @csv
The only problem is the table can have multiple IDs, and I only want each occurrence once. I tried adding a "DISTINCT" before the ID but it doesn't like being there.