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
 General SQL Server Forums
 New to SQL Server Programming
 Storing XML resultset in SQL SERVER tables

Author  Topic 

Amit-1234
Starting Member

19 Posts

Posted - 2015-03-03 : 07:41:31
Hi,

I want to insert a query generated XML resultset into a target table which has a column of datatype "XML". Please find the query as below:

insert into [dbo].[SAMPLEXML]
Select [EMPNO],[EmpFirst],[EmpSurname]
from [dbo].[GW_MPOLA]
FOR XML RAW ('Employee'), Root ('Emloyees'),elements

This query is throwing the following error as below :

Msg 6819, Level 16, State 1, Line 8
The FOR XML clause is not allowed in a INSERT statement.

Kindly help and suggest a possible solution

ahmeds08
Aged Yak Warrior

737 Posts

Posted - 2015-03-03 : 08:33:59

can you try this?

insert into [dbo].[SAMPLEXML] select(
Select [EMPNO],[EmpFirst],[EmpSurname]
from [dbo].[GW_MPOLA]
FOR XML RAW ('Employee'), Root ('Emloyees'),elements)

Javeed Ahmed
https://www.linkedin.com/pub/javeed-ahmed/25/5b/95
Go to Top of Page

Amit-1234
Starting Member

19 Posts

Posted - 2015-03-03 : 09:32:55
It worked. Thank you so much ..:)
Go to Top of Page
   

- Advertisement -