Thursday, September 24, 2009

70-433 SQL Server - Query() method on XML elements

Setup example XML element:


declare @myXML xml

SET myXML = '

   

    eve

    matthey

 

 

    stef

    amar

 

 

    miriam

    tricky

 


Query example XML element:


Select @myXML.query('{/Root/employee[@employee=2]/surname}};


Expected results


amar


Reusing myXML, we could use sp_xml_preparedocument and OPENXML


DECLARE @docHandle int

EXEC sp_xml_preparedocument @docHandle, @myXML


No comments: