Table a:
+------+------+------+--------------------------------------+
| col1 | col2 | col3 | Col4 |
+------+------+------+--------------------------------------+
| 1 | A | E |<?xml version .....<v> "OOOO"</v></vs>|
| 2 | B | F |<?xml version .....<v> "KKKK"</v></vs>|
| 3 | C | G |<?xml version .....<v> "LLLL"</v></vs>|
| 4 | B | E |<?xml version .....<v> "MMMM"</v></vs>|
| 5 | T | G |<?xml version .....<v> "NNNN"</v></vs>|
+------+------+------+--------------------------------------+
How would I update the xml between the ""?
Below is my attempt, which results in updating col4 to NewValue 1 - x. Basically it doesn't keep the xml format.
UPDATE sf
SET sf.col4 =
(CASE col4
WHEN '%OOOO%'
THEN '%NewValue1%'
WHEN '%KKKK%'
THEN '%NewValue2%'
WHEN '%LLLL%'
THEN '%NewValue3%'
WHEN '%MMMM%'
THEN '%NewValue4%'
WHEN '%NNNN%'
THEN '%NewValue5%'
END)
Expected Result:
+------+------+------+-------------------------------------------+
| col1 | col2 | col3 | Col4 |
+------+------+------+-------------------------------------------+
| 1 | A | E |<?xml version .....<v> "NewValue1"</v></vs>|
| 2 | B | F |<?xml version .....<v> "NewValue2"</v></vs>|
| 3 | C | G |<?xml version .....<v> "NewValue3"</v></vs>|
| 4 | B | E |<?xml version .....<v> "NewValue4"</v></vs>|
| 5 | T | G |<?xml version .....<v> "NewValue5"</v></vs>|
+------+------+------+-------------------------------------------+
Col4 is data type : nvarchar(MAX)