John
John

Reputation: 1913

How to filter xml nodes in sql server?

How to add second condition to the following query?

SELECT c.value('@tray','VARCHAR(MAX)')
  FROM @L_XML.nodes('/XDOC/DOC[@TYPE="Q"]') T(c)     

so that I could filter on attribute: type = Q or S?

Where Can I find a detailed manual about xml nodes?

Upvotes: 2

Views: 3044

Answers (2)

Mikael Eriksson
Mikael Eriksson

Reputation: 138980

SELECT c.value('@tray','VARCHAR(MAX)')
FROM @L_XML.nodes('/XDOC/DOC[@TYPE = ("Q", "S")]') T(c)  

Upvotes: 4

Wim Ombelets
Wim Ombelets

Reputation: 5265

A very good starting point is SQLXML where an exhaustive list of basic reads and writes are covered on a How To basis. Quite handy and certainly worth a bookmark in my book!

In regard to your first question: have a look here, that might give you what you're looking for. I think your problem might be in the quotes.

Upvotes: 1

Related Questions