gpt4 book ai didi

sql-server - SQL Server xml.modify 删除方法

转载 作者:数据小太阳 更新时间:2023-10-29 01:59:15 25 4
gpt4 key购买 nike

我在从节点中删除属性时遇到问题。

例子:

DECLARE @processID int
SET @processID = 8

DECLARE @xml XML
SET @xml =
'<Process id="10" name="Test 1">
<Shapes>
<Shape id="1" name="Shape 1" subProcessID="8">
</Shape>
<Shape id="2" name="Shape 2" subProcessID="9">
</Shape>
</Shapes>
<Lines />
</Process>'

SET @xml.modify('delete (/Process/Shapes/Shape/@subProcessID[/Process/Shapes/Shape/@subProcessID = sql:variable("@processID")])')
SELECT @xml

给出结果:

<Process id="10" name="Test 1">
<Shapes>
<Shape id="1" name="Shape 1" />
<Shape id="2" name="Shape 2" />
</Shapes>
<Lines />
</Process>

我想要的是:

<Process id="10" name="Test 1">
<Shapes>
<Shape id="1" name="Shape 1" />
<Shape id="2" name="Shape 2" subProcessID="9" />
</Shapes>
<Lines />
</Process>

实现这个的语法是什么?

最佳答案

由于 OP 已经消失,但他在评论中留下了解决方案,让我将其添加为答案:

DECLARE @processID int
SET @processID = 8

DECLARE @xml XML
SET @xml =
'<Process id="10" name="Test 1">
<Shapes>
<Shape id="1" name="Shape 1" subProcessID="8">
</Shape>
<Shape id="2" name="Shape 2" subProcessID="9">
</Shape>
</Shapes>
<Lines />
</Process>'

SET @xml.modify('delete (/Process/Shapes/Shape[@subProcessID = sql:variable("@processID")]/@subProcessID)')
SELECT @xml

这里是 a working sqlfiddle为此。

关于sql-server - SQL Server xml.modify 删除方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/378431/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com