任何人都可以帮忙 每当要在xml集合中找到我的searchig的值时,我想修改xml集合内的所有节点。我要写的内容是在sqlserver中
在此示例中,我想用“ xxx”替换集合中所有GroupID = 1包括我用于搜索的值(在这种情况下为GroupID)的节点
预先感谢:)
<docID>1234</docID>
<GENERAL>
<general>
<GroupID>1</GroupID>
<name>Sarah</name>
<surname>Benassi</surname>
</general>
<general coll="1">
<GroupID>1</GroupID>
<name>Sarah</name>
<surname>Benassi</surname>
</general>
<general coll="3">
<GroupID>2</GroupID>
<name>Nessar</name>
<surname>Bes</surname>
</general>
</GENERAL>
我已经尝试过了,但是只替换了第一个集合
Declare @id int = "1"
Update Table
set column.modify('replace value of (//general/name/GroupID)[sql:variable("@id")]/]/text())[1] with "XXX"')
Where docId='1234';
Update Table
set column.modify('replace value of (//general/surname/GroupID)[sql:variable("@id")]/]/text())[1] with "XXX"')
Where docID='1234';
Update Table
set column.modify('replace value of (//general/GropuID/GroupID)[sql:variable("@id")]/]/text())[1] with "XXX"')
Where docID='1234';
我期望的结果
<docID>1234</docID>
<GENERAL> <general> <GroupID>xxx</GroupID> <name>xxx</name> <surname>xxx</surname> </general> <general coll="1"> <GroupID>xxx</GroupID> <name>xxx</name> <surname>xxx</surname> </general> <general coll="3"> <GroupID>2</GroupID> <name>Nessar</name> <surname>Bes</surname> </general> </GENERAL>