Search This Blog

Tuesday, March 26, 2013

XML query() Method SQL Server

Specifies an XQuery against an instance of the xml data type.

Example:


declare @Doc xml
set @Doc = '<Root>
<Order OrderID="1" CustomerName="John">
       <Items>
             <Item>Item 1</Item>
             <Item>Item 2</Item>
       </Items>
</Order>
</Root>'


SELECT @Doc.query('/Root/Order/Items')

Reult:

<Items>
  <Item>Item 1</Item>
  <Item>Item 2</Item>
</Items>