<Component>
<Caption>2 7/8" x 1",Drill Collar,2 3/8 PAC</Caption>
<Description>2 7/8" x 1",Drill Collar,2 3/8 PAC</Description>
<Count>1</Count>
<Sections>
<Section>
<Material>Steel AISI 4145</Material>
<Connection>2 3/8 PAC</Connection>
<Weight>28.7197</Weight>
<Length>0.508</Length>
</Section>
<Section>
<Material>Steel AISI 4145</Material>
<Connection>NC50</Connection>
<Weight>28.7197</Weight>
<Length>0.508</Length>
</Section>
<Section>
<Material>Steel AISI 4145</Material>
<Connection>NC36</Connection>
<Weight>28.7197</Weight>
<Length>0.508</Length>
</Section>
</Sections>
</Component>
我在 SQLServer 2008 R2 中有一个组件表,它有一个 PK ID 字段和另一个 XML 类型的列。在那个 XML 列中,我的 XML 看起来像您在上面看到的。对于每一行,我想修改所有嵌套的 Section 块,使它们每个都有两个额外的元素。这是我尝试过的,它只将新元素插入到第一个 Section 块中......但不是其他两个。
DECLARE @MaxFeatures XML
SET @MaxFeatures = N'<MaxAllowableTorque>0</MaxAllowableTorque>
<MaxAllowableForce>0</MaxAllowableForce>'
Update Component
SET XMLDetails.modify('
insert sql:variable("@MaxFeatures")
after (/Component/Sections/Section/Length)[1]
')