Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Updating XML attributes using a lookup table

Author  Topic 

satty.fl
Starting Member

1 Post

Posted - 2012-12-18 : 15:40:46
Hello,


I want to update all the attribute values inside all the nodes (name) that matches a look up table (lookup table has Name and ID) with the Id of the look up table.

Sample XML:
<SECTION NAME="Classes">
<ITEM NAME="1309" />
<ITEM NAME="1335" />
<ITEM NAME="1375" />
<ITEM NAME="1387" />
<ITEM NAME="1537" />
<ITEM NAME="1539" />
</SECTION>

Please help me with this.

Thanks

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-12-18 : 16:13:43
You can conceivably use the modify method in XQuery, (see here and the links on that page. But the modify method is rather limited and inflexible in my experience unless you are trying to do simple modifications. If your XML is as simple as you have shown in the example, it is perhaps easier to shred the XML into a relational (virtual) table, make the changes you need to and reconstitute the XML.

If you can post the DDL, sample data and desired output, people on the forum should be able to use the approach I outlined above, or another approach. If you need help in posting, take a look at this page
Go to Top of Page
   

- Advertisement -