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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 XQuery : Combining results

Author  Topic 

rzurer
Starting Member

1 Post

Posted - 2008-11-21 : 08:09:30
I want to send one row containing xml created from all rows returned by an XQuery statement. Is this possible?

This query returns 10 rows:

SELECT MyXmlColumn.query('//Foo') FROM MyTable;
I want to add an enclosing element, add each element from the results and send back one row.

When I assign the results to a variable

DECLARE @x XML;
SELECT @x = MyXmlColumn.query('//Foo') FROM MyTable;
and then call SELECT @x, It only contains the last row not all 10
Calling SELECT @x.query('count(.)') therefore returns 1.

My idea was to put all 10 results in a variable and then create a single document to send back, but no joy.

I also researched the XQuery collection() function but that is not supported in Sql Server.

Obviously I am not understanding some completely basic concept.

Any thoughts?

TIA

Robert Zurer







visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-21 : 08:46:38
how is your xml structure?
Go to Top of Page
   

- Advertisement -