I am trying to create a comma delimted list of names in a table using the below query
DECLARE @listStr VARCHAR(MAX)
SELECT @listStr = COALESCE(@listStr+',' ,'') + Name
FROM Production.Product
SELECT @listStr
This works fine, however the list does contain duplicates
Can anyone advise how I would make this DISTINCT
so the list does not contain duplicates.
Is it useful ?
DECLARE @listStr VARCHAR(MAX)
SELECT @listStr = COALESCE(@listStr+',' ,'') + name
FROM (SELECT DISTINCT name FROM Production.Product) t
SELECT @listStr
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With