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