views:

159

answers:

1

Am trying to insert XML into XML Column.. getting following error: .

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

My SQL query

declare @tempTable Table (xmlValue xml)
insert into @tempTable
select EmployeeName, EmployeeSalary from Employee2
for xml path('EmployeeDetails')

what am i doing wrong

+1  A: 

As the error says, you can't use FOR XML in the body of an INSERT statement. You have to wrap the part that retrieves the XML:

DECLARE @tempTable TABLE
(
    xmlValue xml
)

INSERT @tempTable (xmlValue)
SELECT
(
    SELECT EmployeeName, EmployeeSalary
    FROM Employee2
    FOR XML PATH('EmployeeDetails')
)
Aaronaught