We are storing an XML document of all the different costs in SQL Server 2008 r2. Now, certain prices need to be update based on a formula.
One approach to this would be to:
- Shred the XML and access the values.
- Do the calculation
- Now rebuild the XML structure.
Is this the only way to do it? Or is there an easier way where we can access the values on the fly and update the entire XML in one go? For this kind of scenario, what is the best approach?
Here is the sample of the XML:
<ItemAttributeData>
<Section ID="469919" TypeID="61000002">
<Attributes>
<Attribute ID="3870" UniqueID="1c71212b-8395-4b43-a44d-9a63374c8c99" VALUE="2" />
<Attribute ID="3569" UniqueID="c0b754d3-e03e-4d4a-9bc1-dcb11c04535b" VALUE="2" />
<Attribute ID="1592" UniqueID="2609b344-88b2-44d6-be20-07b634705c30" VALUE="2" />
</Attributes>
</Section>
<Section ID="469920" TypeID="61000001">
<Attributes>
<Attribute ID="3702" UniqueID="7cabf9e8-4f60-4e1e-afe5-75b153e8c5eb" VALUE="1000001649" />
<Attribute ID="3870" UniqueID="595f8e2c-bccb-4fcb-81d4-303fcb7d44c4" VALUE="2" />
<Attribute ID="3868" UniqueID="2226f6c6-380a-4195-98f7-c6deec84e4e8" VALUE="2" />
<Attribute ID="3754" UniqueID="bf936c3f-fa96-49b9-8a62-46fb7e0009d5" VALUE="1000001600" />
<Attribute ID="2204" UniqueID="bdc78784-86ad-4567-bc06-40896d603eaf" VALUE="1" />
<Attribute ID="3874" UniqueID="8728249f-5e60-4938-a60d-208426fe11c8" VALUE="1" />
</Attributes>
</Section>
<Section ID="469921" TypeID="61000001" />
</ItemAttributeData>