<Address>下,xml存储可以有零个或多个<Addresses>节点。
需要查询以删除其<Address>的任何<AddressLine> = '2 Church Lane'节点
开始XML:

declare @t table (storage xml);
insert into @t (storage)
select '<Person>
  <Fullname />
  <Surname>Smith</Surname>
  <FirstName>John</FirstName>
  <Addresses>
      <Address>
        <AddressLine>1 Church Lane</AddressLine>
      </Address>
      <Address>
        <AddressLine>2 Church Lane</AddressLine>
      </Address>
      <Address>
        <AddressLine>3 Church Lane</AddressLine>
      </Address>
  </Addresses>
</Person>';

结果XML:
<Person>
  <Fullname />
  <Surname>Smith</Surname>
  <FirstName>John</FirstName>
  <Addresses>
      <Address>
        <AddressLine>1 Church Lane</AddressLine>
      </Address>
      <Address>
        <AddressLine>3 Church Lane</AddressLine>
      </Address>
  </Addresses>
</Person>

最佳答案

找到它:

update @t
SET storage.modify('
    delete (/Person/Addresses/Address[AddressLine = "2 Church Lane"])
')

09-08 06:28