我从节点中删除属性时遇到问题.
例:
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
Run Code Online (Sandbox Code Playgroud)
给出结果:
<Process id="10" name="Test 1">
<Shapes>
<Shape id="1" name="Shape 1" />
<Shape id="2" name="Shape 2" />
</Shapes>
<Lines />
</Process>
Run Code Online (Sandbox Code Playgroud)
我想要的是:
<Process id="10" name="Test 1">
<Shapes>
<Shape id="1" name="Shape 1" />
<Shape id="2" name="Shape 2" subProcessID="9" />
</Shapes>
<Lines />
</Process>
Run Code Online (Sandbox Code Playgroud)
实现这个的语法是什么?
由于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
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5188 次 |
最近记录: |