We help IT Professionals succeed at work.
Get Started

Building a string from an xml

186 Views
Last Modified: 2016-06-07
Hello!

Can someone help me with some sql that will return to me some data from an xml object?

I have the following xml:
<root>
  <FromDate>2016-03-01</FromDate>
  <ToDate>2016-03-25</ToDate>
  <Variables>
    <Variable>
      <Name>pain</Name>
    </Variable>
    <Variable>
      <Name>unit</Name>
    </Variable>
  </Variables>
  <Filters>
    <Filter>
      <Name>diagnose</Name>
      <Values>
        <Value>1461</Value>
        <Value>1462</Value>
      </Values>
    </Filter>
  </Filters>
</root>

Open in new window

I would like to extract the text of the <Value> nodes under the <root> <Filters> <Filter><Values> where the text in <root> <Filters> <Filter><Name> is "diagnose".

The resuting nvarchar should be "1461, 1462"

I am used to building strings like this from tables using something like:
 select @CategoryAxis = @CategoryAxis + '<Category>' +cast( measurementdate as nvarchar(12) ) + '</Category> ' from MeasurementStatisticsPerUnit

Open in new window

but i just cannot get my head arround XML.
Comment
Watch Question
Business Intelligence Developer and Analyst
CERTIFIED EXPERT
Top Expert 2015
Commented:
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE