• I did something similar the other month to demonstrate the use of XML data, and how to remove the dreaded cursors from the code, granted it was written on an intitally small set and there was not requirement for Ordering the data in the output list.

    The main difference was that I prefixed the list with a Comma, this mean that I could simply do a substring(XMLString,2,4000), the code looked like this

    Select Distinct

    EmployeeID

    ,Substring(Replace

    (Replace((Select ','+SkillData

    From #tmp

    where EmployeeID=a.EmployeeID

    FOR XML RAW),'<Row Data="',''),'"/>',''),2,4000) Data

    from #tmp a

    The XML data before the Replace is run looked like

    <row Data=",UU"/><row Data=",WW"/><row Data=",XX"/><row Data=",ZZ"/>

    After the replace you had a string that looked like this ",UU,WW,XX,ZZ"

    The downside is the distinct has on large data sets it could have an impact.

    Having said that I do like the look of some of the pure T-SQL scripts.

    _________________________________________________________________________
    SSC Guide to Posting and Best Practices