T-SQL Convert multiple rows to comma separated String

JDCam
JDCam used Ask the Experts™
on
The below query returns 17 unique reference numbers from 400+ rows

select 
Distinct(Ref_Num) 
from DAY_943 where Unique_Ref = '00138AMCR2018-04-21'

Open in new window

I need to output this as a single comma separated string.
By googling I see methods using CTE and XML Path, but not having much luck
Can anyone give me a hand with this Please.

I am using Mangement Studio 2014
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
I got it to work with this.
SELECT Distinct(Ref_num) + ', ' AS 'data()' 
FROM DAYCO_943 
where Unique_Ref = '00138AMCR2018-04-21'
FOR XML PATH('')

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial