Avatar of Star79
Star79Flag for United States of America asked on

Reading an xml file from SQL

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

Microsoft SQL Server 2005Microsoft SQL Server 2008

Avatar of undefined
Last Comment
Anthony Perkins

8/22/2022 - Mon
unknown_routine

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

  ?
ASKER
Star79

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>
ASKER CERTIFIED SOLUTION
unknown_routine

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Anthony Perkins

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.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck