1

I am trying to insert a XML into a SQL Server table, but I get an error:

Msg 2205, Level 16, State 1, Line 10
XQuery [value()]: ")" was expected.

Code:

 DECLARE @XML XML = '<list>
    <object Index="0"   Type="0"    Name="obj1" Level="6" />
    <object Index="1"   Type="0"    Name="obj2" Level="9"    />
</list>'
INSERT INTO dbo.testt(test1, test2, test3, test4)
SELECT
    test1 = Events.value('@Index','int'),
    test2 = Events.value('@Type','varchar'),
    test3 =Events.value('@Name','varchar'),
    test4 =Events.value('(@Level','int')
FROM
 @XML.nodes('/list/object') AS testtt(Events)

Thank you!

1 Answer 1

3

You have a ( before @Level

test4 =Events.value('(@Level','int')

should be:

test4 =Events.value('@Level','int')
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.