Re: XQuery vs OpenRowset



Shilpa (shilpa.nagavara@xxxxxxxxxx) writes:
Please let me know the advantages and disadvantages of XQuery vs
OpenRowSet in SQL Server 2005. Which would be better?

I'm by no means an expert on XML, but I would say that XQuery is
preferrable for all new code that you write. It may not be worth
to rewrite legacy code just for the sake of it.

A major advantage is that you don't need this sp_xml_preparedocument
with XQuery.

Of course, if all you want to do is to unpack an XML document, using
nodes() and CROSS APPLY may feel bulkier, at least initially when the
new syntax may feel akward. Then again, XQuery permits you to do a
lot more things that OPENXML does not, so that you can query an XML
document withour shredding it.

There is one situation you will have to stick to OPENXML, and that is
if you for for some reason are running with any of the options
QUOTED_IDENTIFIER, ANSI_NULLS, ANSI_WARINGS, ANSI_PADDING or
CONCAT_NULL_YIELDS_NULL off. They must be on for XQuery. Note that some
of these options are sticky with stored procedures or table columns.


--
Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
.



Relevant Pages

  • Re: Nested Nodes in XML from a table
    ... > Thanks Erland, it works now. ... > extension, added the missing XML declaration line, SQL Server didn't ... > queries from SQL Server, but i rather create XML file and read from it ... but please look in Books Online. ...
    (comp.databases.ms-sqlserver)
  • Re: Help me with this query please.
    ... When I look at the examples for FOR XML EXPLICIT ... A more normal document would be: ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ... Books Online for SQL Server 2005 at ...
    (comp.databases.ms-sqlserver)
  • Re: Shred XML to SQL 2005
    ... but only with simple XML Docs. ... there are two methods: OPENXML and XQuery. ... Both OPENXML and XQuery are described in Books Online, ... "Programming Microsoft SQL Server 2000 with XML" by Graeme Malcolm. ...
    (comp.databases.ms-sqlserver)
  • Re: FOR XML not working in a subquery
    ... Why can't this be done in SQL Server 2000? ... have used extensively in SQL Server 2000--why the problem with FOR XML? ... Retrieving and Writing XML Data -> ... Books Online for SQL Server 2005 at ...
    (comp.databases.ms-sqlserver)
  • Re: Getting all nodes and node details from xml using xquery
    ... Since I'm no specialist in XML, I've consulted my MVP colleagues who know ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ... Books Online for SQL Server 2005 at ...
    (comp.databases.ms-sqlserver)