FOR XML PATH
column aliases are XPath-like paths; PATH('') with no column name concatenates values
What changes
- Input
- final ordered result rows
- Output or change
- one XML value or a concatenated string
Syntax at a glance
FOR XML PATH [ ( 'ElementName' ) ]
Work example
A client needs FOR XML PATH to serialize a query result into a named document shape.
Use two synthetic rows and specify stable aliases. Check escaping, null handling, and nested property names in the emitted text.
Check your work FOR XML PATH. The output from FOR XML PATH parses as the expected document and preserves the requested field names.
Open Microsoft Learn for full syntax, permissions, and details for your version.