• FOR XML is one of the best tools in MSSQL but I would regard it as something that only a power user should attempt as it's syntax is confusing.

    Basically it allows you to take an undefined number of records with a related key and convert them into a nested XML Group to pass on to other systems in a structured format (E.g. to be consumed by a webservice)

    <BOOKS>

    <BOOK>Wizard of Oz </BOOK>

    <BOOK>Frankensteins Monster</BOOK>

    <BOOK>Moby Dick</BOOK>

    </BOOKS>

    Building comma separated lists is the same concept except instead of <BOOK>...</BOOK> we will just use ' , '

    I would say don't worry about how it works, just play with the different parts to see what effect is has on the output. This will allow you to adapt the example to your real code.