Follow the rest of this series at the XQuery for the Non-Expert
– X-Query Resources introduction post. The main use for the
query() method is to retrieve child elements by browsing down to
lower levels of an XML document. Sometimes when the nodes()
method is used to browse through an XML document you need to
retrieve the XML fragment that was queries. The query() method
can be used to return the XML fragment. The general syntax for
the query() method is The XQuery statement that directs the
query() method how to browse the XML document or fragment. For a
more detailed explanation of the XQuery statement, read my post
on the nodes() method. The query() function is called as a
method off of the column that contains the XML data. This method
can be called the SELECT statement. To illustrate the two
methods listed above for using the query() method let’s setup a
table with an XML document. Run the following query to get
everything setup for the examples below: IF
OBJECT_ID('tempdb..#QueryExample') IS NOT NULL DRO