Wednesday, March 7, 2012

Format Table Row into XML and Insert into Another Table?

First I am using SQL Server 2000 (I think this is easy to do in 2005)

I am trying to do the following:

- Format a table row into an XML string

- Insert the XML string into another table.

Here is what I want to do in a nutshell:

insert into Table1(xml_data)

select * from customers

where customerid = 'alfki'

for xml auto, elements

However, I get the following error: The FOR XML clause is not allowed in a INSERT statement.

I tried a few other formats, such as User Defined Function and etc.

Can this be done? Any ideas?

R

This is not possible in SQL Server 2000 without going through lot of pain on the server-side. So best is to get the XML data to the client and then insert from there.

No comments:

Post a Comment