删除多个XML属性

时间:2014-04-28 07:09:13

标签: sql-server xml tsql sql-server-2012

有没有办法统一以下陈述:

UPDATE @Test
SET [XML].modify('delete (Settings/@attributefordeletion1)[1]')

UPDATE @Test
SET [XML].modify('delete (Settings/@attributefordeletion2)[1]')

UPDATE @Test
SET [XML].modify('delete (Settings/@attributefordeletion3)[1]')

2 个答案:

答案 0 :(得分:3)

update @Test
set [XML].modify('delete (
                         Settings/@attributefordeletion1, 
                         Settings/@attributefordeletion2, 
                         Settings/@attributefordeletion3
                         )')

或者如果要删除所有属性

update @Test
set [XML].modify('delete Settings/@*')

答案 1 :(得分:1)

发现了删除属性集的另一种方法:

update @Test
set [XML].modify('delete Settings/@*[local-name()=(
                                    "attributefordeletion1",
                                    "attributefordeletion2", 
                                    "attributefordeletion3"
                                    ]')