Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 xml reseultset in sql

Author  Topic 

subhaoviya
Posting Yak Master

135 Posts

Posted - 2012-09-27 : 07:46:34
Hi,
I have a table t1 with column xml1.
the xml1 has the value like

in row 1
<ROOT>
<MyVal v1="a">
<MyVal v1="b">
<MyVal v1="c">
<MyVal v1="d">
</ROOT>

in row 2
<ROOT>
<MyVal v1="u">
<MyVal v1="v">
<MyVal v1="g">
<MyVal v1="j">
</ROOT>

I need th resultset

a
b
c
d
u
v
g
j

how to get this? using xpath?

thanks
subha

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-09-27 : 07:55:09
Like this:
SELECT
c.query('data(@v1)') AS v1
FROM
t1
CROSS APPLY xml1.nodes('/ROOT/MyVal') t2(c);
Go to Top of Page
   

- Advertisement -