• reto.eggenberger (1/12/2011)


    Thank you for this tip with the STUFF function.

    Is the order by in the subquery really needed? I think the for xml does it anyways. If you don't use the order by; you may use distinct to get every value only once.

    The order by in the subquery is used to control the ordering of the elements in the XML. If you don't use it, then there is no guarantee as to the order. You can use the distinct (or group by) to get each value once. This is independent of the order by clause.

    Wayne
    Microsoft Certified Master: SQL Server 2008
    Author - SQL Server T-SQL Recipes


    If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
    Links:
    For better assistance in answering your questions
    Performance Problems
    Common date/time routines
    Understanding and Using APPLY Part 1 & Part 2