将XML导入SQL Server

时间:2015-03-31 13:55:31

标签: sql-server xml

我正在尝试将XML插入到SQL Server表中,但是我收到错误:

  

Msg 2205,Level 16,State 1,Line 10
  预计XQuery [value()]:“)”。

代码:

 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)

谢谢!

1 个答案:

答案 0 :(得分:3)

(之前有@Level

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

应该是:

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