Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Iam trying to convert data table to xml. It works fine. Now i want to store this converted xml in another table, So i tried using insert into select statement, it throws an error as "
Quote:
The FOR XML clause is not allowed in a INSERT statement.
"

here is my query, kindly resolve this problem.

insert into table1(column1)select*from table2 for xml raw('product'),root('productDetails');

What I have tried:

insert into table1(column1)select*from table2 for xml raw('product'),root('productDetails');
Posted
Updated 18-Jan-18 23:16pm

1 solution

DECLARE @temporaryTable tmpTbl
(
    xmlValue xml
)

INSERT @tmpTbl (xmlValue)
SELECT
(
    SELECT XColumn, YColumn
    FROM table2 
    FOR XML PATH('productDetails')
)
Insert into table1 select * from tmpTbl
DROP tmpTbl;


Don't just copy paste as this is not tested.It may throw some syntax error.
 
Share this answer
 
v2
Comments
Vinodh Muthusamy 19-Jan-18 6:36am    
could please explain this query or alter it to working query

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900