Reading an xml file from SQL

Star79
Star79 used Ask the Experts™
on
Hello,
I have a table monographs and the data has filecontent which is a xml.When I run the below query it returns me the row for that drug.Now how can I search for all the filecontent which has <warnbox> as one of the xml tags as the below filecontent for this drug has warnbox as one of its tag,so basically Iam looking for all the filecontent which has this tag.Please help.



SELECT *
  FROM Monographs
  WHERE CAST(filecontent  AS VARCHAR(MAX)) LIKE '%abacavir%'

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
I think your question is not clear enought.

your query

SELECT *
  FROM Monographs
  WHERE CAST(filecontent  AS VARCHAR(MAX)) LIKE '%abacavir%'

Open in new window


Will return all filecontent with the abacavir in them?

What's wrong with


SELECT *
  FROM Monographs
  WHERE CAST(filecontent  AS VARCHAR(MAX)) LIKE '%warnbox%'

Open in new window

  ?

Author

Commented:
true it actually works.
Another extension to this question.The file has a set of tag like below:how can I extract anything thats between generic-name tag.
Thanks.
<title>
      <generic-name>Azathioprine</generic-name>
      <doseform>Tablets</doseform>
    </title>
Take a look here:
http://blog.sqlauthority.com/2009/02/13/sql-server-simple-example-of-reading-xml-file-using-t-sql/

however it is usually not the duty of DB layer to manipulate XML data, but DB sends this info to Businees layer to do the processing.
Top Expert 2012

Commented:
so basically Iam looking for all the filecontent which has this tag.
You use the Xml Data Type Methods to filter the data you need.

If you can post a sample of your Xml and what nodes to filter on I can post an example.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial