I have a XML column called xmlValue in a SQL Server table tbl1 with datatype nvarchar(max).
The xml value in this column looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<main>
<sub>
<subMode>
<name>abc</name>
<address>add abc</address>
</subMode>
<subMode>
<name>xyz</name>
<address>add xyz</address>
</subMode>
<sub>
</main>
Currently, the address value of name 'xyz' is 'add xyz'. I need to update it to something else say 'add xyz updated'.
Is there any simple way to do this.
I tried using solution provided in How to Update XML in SQL based on values in that XML but it seems complicated.
Do anyone has a simpler solution to achieve this?
You were told already, that your XML should be stored as native XML.
Your problem is multifolded
NVARCHAR(MAX)instead ofXML)NVARCHARis not allowed with a declaration statingUTF-8encoding.modifyis not applicable on the flySo the workaround is a temp table
A mockup scenario
--This
SELECTconverts your string-XML and stores the result as real XML--Your search for xyz and append something to the existing value
--Now you update the original tabel using an
INNER JOINto the temp table--The result (and clean-up)