SQL Server xml.modify删除方法

5 xml sql-server

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

例:

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)

实现这个的语法是什么?

ren*_*ene 1

由于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)

这是一个有效的 sqlfiddle