Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在XML节点中添加多个属性_Xml_Tsql_Insert_Sql Server 2012 - Fatal编程技术网

在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

我想为所有节点添加两个新属性。所有元素的属性名称和值都相同

我有以下XML结构:

<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]')