all groups > sql server programming > may 2006 >
You're in the

sql server programming

group:

Simple XQuery Syntax Question



Simple XQuery Syntax Question PJ
5/16/2006 11:58:23 PM
sql server programming: /*
I am trying to extract a subset of nodes from multiple xml instances into
one instance, but I do now know the proper syntax. Can someone please help
me out? Finally starting to learn XQuery! See below for DDL and desired
result.

Thanks so much!!
~PJ
*/

create table XmlDataTable (
Instance xml
)
go
insert XmlDataTable ( Instance ) values ('<root><node>node 1</node></root>')
insert XmlDataTable ( Instance ) values ('<root><node>node 2</node></root>')
go


/*
I would like to know the proper XQuery Syntax to return this result
<root>
<node>node 1</node>
<node>node 2</node>
</root>
*/
-- this is not right as it returns multiple instances
select
instance.query('
<root>
{
for $r in /root
return $r/node
}
</root>')
from xmldatatable

drop table XmlDataTable

Re: Simple XQuery Syntax Question Han
5/17/2006 12:00:00 AM
[quoted text, click to view]

I think you want this,

select instance.query('/root/node')
from xmlDatatable
for xml path(''), root('root')
RE: Simple XQuery Syntax Question Omnibuzz
5/17/2006 1:46:02 AM
I am as new to this as you.
But may be you can try this..

select cast((select instance.query('/root/node') from
XmlDataTable
for xml path('')) as XML) as 'root'
Re: Simple XQuery Syntax Question PJ
5/17/2006 10:47:22 AM
Works great! Love the FOR XML PATH...good bye FOR XML EXPLICIT!


[quoted text, click to view]

AddThis Social Bookmark Button