O'Reilly logo

Microsoft® SQL Server 2012 Unleashed by Alex T. Silverstein, Chris Gallelli, Paul T. Bertucci, Ray Rankins

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

PATH Mode

PATH mode is the latest and best addition to the FOR XML syntax. It provides a straightforward way of using a limited XPath syntax to specify the shaping of query-produced XML. It is also a very compact syntax in comparison with some of the other modes, especially EXPLICIT.

Let’s look at how PATH mode works by re-creating the XML produced in Listing 49.9, this time using PATH mode. Listing 49.10 illustrates this mode.

LISTING 49.10 Using FOR XML PATH to Simplify an EXPLICIT Query

SELECT    Reason.ScrapReasonId,    Name 'text()',    WorkOrderId 'WorkOrder/@WorkOrderId',    ScrappedQty 'WorkOrder/@ScrappedQuantity'FROM Production.ScrapReason ReasonJOIN Production.WorkOrder WorkOrderON Reason.ScrapReasonId ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required