nodes() Method
XML shredding
What changes
- Input
- xml instance and XQuery
- Output or change
- rowset: one row per matching node (context for value()/query())
Syntax at a glance
nodes (XQuery) as Table(Column)
Work example
Turn repeated XML elements into a rowset for a relational report.
Choose the repeating element path and extract each field from the resulting context node.
Check your work nodes creates one row per matching node and its output is an XML context used by other methods.
Practice SQL
Open in SQL FlowDECLARE @doc xml = N'<Orders><Order id="1" /><Order id="2" /></Orders>'; SELECT O.N.value('(@id)[1]', 'int') AS order_id FROM @doc.nodes('/Orders/Order') AS O(N);
Open Microsoft Learn for full syntax, permissions, and details for your version.