SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 xml reseultset in sql
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

subhaoviya
Posting Yak Master

India
135 Posts

Posted - 09/27/2012 :  07:46:34  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

5155 Posts

Posted - 09/27/2012 :  07:55:09  Show Profile  Reply with Quote
Like this:
SELECT
	c.query('data(@v1)') AS v1
FROM
	t1
	CROSS APPLY xml1.nodes('/ROOT/MyVal') t2(c);
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000