XMLQUERY function for retrieval of portions of an XML document

XMLQUERY is an SQL scalar function that lets you execute an XQuery expression from within an SQL context.

You can pass variables to the XQuery expression specified in XMLQUERY. XMLQUERY returns an XML value, which is an XML sequence. This sequence can be empty or can contain one or more items.

When you execute XQuery expressions from within an XMLQUERY function, you can:
  • Retrieve parts of stored XML documents, instead of entire XML documents.
  • Enable XML data to participate in SQL queries.
  • Operate on both relational and XML data in the same SQL statement.
  • Apply further SQL processing to the returned XML values (for example, ordering results with the ORDER BY clause of a subselect), after you use XMLCAST to cast the results to a non-XML type.

XQuery is case-sensitive, so you need to ensure that the case of variables that you specify in an XMLQUERY function and in its XQuery expression match.