在XML节点中添加多个属性
我想为所有节点添加两个新属性。所有元素的属性名称和值都相同 我有以下XML结构:在XML节点中添加多个属性,xml,tsql,insert,sql-server-2012,Xml,Tsql,Insert,Sql Server 2012,我想为所有节点添加两个新属性。所有元素的属性名称和值都相同 我有以下XML结构: <question id="1001"></question> <question id="1002"></question> <question id="1003"></question> <question id="1004"></question> 但我得到了以下错误: Msg 8137, Level 16, S
<question id="1001"></question>
<question id="1002"></question>
<question id="1003"></question>
<question id="1004"></question>
但我得到了以下错误:
Msg 8137, Level 16, State 1, Line 89
Incorrect use of the XML data type method 'modify'. A non-mutator method is expected in this context.
有人知道我做错了什么吗?不幸的是
xml数据类型的modify()方法只能在集合中使用
UPDATE语句的子句
因此,我需要创建一个表变量,在其中插入记录,然后修改xmls
要在一条modify insert语句中添加多个属性,可以使用以下语法:
UPDATE @TempTable
SET XMLColumn.modify('insert (attribute test1 {"1" },attribute test2 {"2"}) into (/question)[1]')
Msg 8137, Level 16, State 1, Line 89
Incorrect use of the XML data type method 'modify'. A non-mutator method is expected in this context.
UPDATE @TempTable
SET XMLColumn.modify('insert (attribute test1 {"1" },attribute test2 {"2"}) into (/question)[1]')