【发布时间】:2020-06-01 13:14:35
【问题描述】:
我有以下 Xml 示例 sn-p 取自一个较大的文件:
<EntityAttributeValue>
<Value />
<Attribute>
<Id>0</Id>
<Name>Use 3</Name>
<AttributeType>other</AttributeType>
</Attribute>
<AttributeValueId>999998</AttributeValueId>
<ProductTypeId xsi:nil="true" />
</EntityAttributeValue>
我正在尝试使用 SQL 删除 <ProductTypeId> 节点,以便上面的内容如下所示:
<EntityAttributeValue>
<Value />
<Attribute>
<Id>13</Id>
<Name>Use 3</Name>
<AttributeType>other</AttributeType>
</Attribute>
<AttributeValueId>999998</AttributeValueId>
</EntityAttributeValue>
我已使用以下 SQL 查询 XML 并隔离上面的 sn-p(第一个)
select t.c.query('.') as Attributes
from @XMLData.nodes('/Item/ContentAttributeValues/EntityAttributeValue') t(c)
where t.c.value('(Attribute/Id)[1]','INT') = 0
我试过了
SET @XMLData.modify('delete (/Item/ContentAttributeValues/EntityAttributeValue/ProductTypeId)')
删除所有产品ID,但无济于事,任何帮助都会得到很大的帮助。
干杯
【问题讨论】:
-
请发布该问题的完整重现,因为
xml.modify(似乎是正确的。
标签: sql-server xml tsql sql-server-2016 xml-dml