Changing value of XML attribute without knowing its exact location

  • This is the first time I'm doing anything serious with XML in SQL Server, so maybe it's really simple. However, my attempts with Google and Books Online failed to turn up anything useful. If it's out there and I'm simply missing it, pointers are appreciated.

    Note that this will end up in a conversion script that runs only once on any real amount of data, so performance is not the critical aspect. Accuracy and completeness is much more important.

    The problem is this:

    I have a set of rows in a database that contains XML (stored in a VARCHAR(MAX) NULL column, which I'm pretty much stuck with). There are two interesting XML elements (actually, there is a multitude, but I can ignore all but two specific ones), and I need to change the value of an attribute deep into the XML. BO points me at XML DML "replace value of" which if nothing else I suppose I could somehow use together with a cursor and some type casting, but the problem is that while I know the structure (quasi-DTD) of each of the XML elements I need to work with, the value that needs to be updated could appear at any place inside the node in question. That is, on one row the value I need to replace might come first, but in the next instance of the same element it could be number 17, 5 or 42 under the same node path.

    So I need to somehow instruct SQL Server 2008 to "wherever this combination of attribute and value appears in a node identified by this path, replace the value with that", whether that matches 0, 1, 2 or n times. How do I do that?

  • Never mind the above - after looking into this further, and consulting with a few colleagues of mine, it was decided to go about doing this in a different way.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply