3

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

0

1 Answer 1

12

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')
)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.