Delete nodes with certain value from XML using TSQL

邮差的信 提交于 2019-12-05 02:57:41

Try

update @XML set data.modify('delete //Message[text()][contains(.,"customer")]')

to delete the <message/> element and its contents

update @XML set data.modify('delete //Message//text()[contains(.,"customer")]')

to delete the <message/> element's contents.

Example here http://msdn.microsoft.com/en-us/library/ms178026.aspx

Thalles Noce
    declare @XML xml = '
    <Root>
      <Sub>
        <Record>
          <Guid>aslkjflaksjflkasjfkljsd</Guid>
        </Record>
        <Record>
           <Guid>opqiwuerl;kasdlfkjawop</Guid>
        </Record>
      </Sub>
    </Root>'

declare @Guid varchar(30) = 'aslkjflaksjflkasjfkljsd'

set @XML.modify('delete /Root/Sub/Record[Guid = sql:variable("@Guid")]')

Reference https://dba.stackexchange.com/questions/40039/how-to-return-xml-node-ordinal-or-delete-node-based-on-element-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!