I've come across a problem in updating an SQL field in that what I've written works perfectly for xml nodes with a text present, however it trips up when the node is empty.
<filemeta filetype="Video">
<heading>TEST</heading>
<description />
</filemeta>
This code works fine;
UPDATE filemetaDB SET filemeta.modify('replace value of (/filemeta/heading/text())[1] with "TEST"');
However this breaks;
UPDATE filemetaDB SET filemeta.modify('replace value of (/filemeta/description/text())[1] with "notworking!"');
Thanks for any help.
you can check if the node has Data before updating such as:
I had a scenario where I ONLY wanted to update the EMPTY nodes.
not(node()) means no children and not(text()) means no text content (possibly has children however, so mix and match these cases as needed)
This node
(/filemeta/description/text())[1]
does not exist in the XML so there is nothing to replace. You have to do an insert instead. If you have a scenario where you have a mix of empty nodes and nodes with a value you have to run two update statements.Result:
I think that this method will not work for empty nodes.
You also coud check this thead: link