Dr. Michael Rys has a great post up on how For Xml nesting will work in Yukon.
Obviously, this query is easier to write, understand and maintain. OTOH, due to the fact that we create intermediate XML objects, it may have worse performance characteristics (altough, sometimes it can be faster since we do not need the union and less joins).
I think the performance hit will be well worth it. Plus if you don't want to take the performance hit you can still use the explicit mode.
This nesting feature also looks like it could be useful for “fixing” something I run into when using Serialization. When I have a collection that I want to populate using a FOR XML query, I've found that you need the root element to be in the form of "ArrayOfType" where "Type" is the type of objects that make up the collection. In order to create the root element I use a simple view:
create view EmptyParentView as select '' as Parent
Then I join this view with my table in a FOR XML AUTO select query:
select Parent as IgnoreMe, -- Ingore this element ReportID, ReportTitlefrom EmptyParentView as ArrayOfReport, Reports as Reportfor xml auto, elements
This gives me an Xml result that can be deserialized into a collection. Would nesting help me? Maybe not since I really wouldn't be able to specify the root element type. Comments?