How to generate a Delimited String is using FOR XML PATH
XQuery Lab 19 – How to parse a delimited string?
I have previously written article about operation of creating a delimited string using COALESCE and no XML but as per telephonic conversation with Jacob COALESCE is only good for one column where as XML can do many more magics.
Jacob has already explained articles in detail so I suggest to read them carefully and digest. If you are not much bigger on XML, you do not have to spend time on learning this XML. Just take the XML script and use it for your need.
If you are wondering what about two articles do, here is a simple explanation. First article explains how to convert Sample 1 to Sample 2 and later one explains how to convert Sample 2 to Sample 1.
XML is very powerful and when combined with SQL Server it always unveils new side of RDBMS and DBMS.
Reference: Pinal Dave (https://blog.sqlauthority.com)