I'm usint MS SQL在XML字段中需要像这样更新。
UPDATE Table
SET
IF (XMLdata.exist('/ns:root/Field/text()') = 0)
XMLdata.modify('
insert text{"New value"}
into (/ns:root/Field)[1]
')
ELSE
XMLdata.modify('
replace value of (/ns:root/Field/text())[1]
with "Replaced value"
'),
WHERE condition
2 个 XML 文件的示例
版本 1
<ns:root ....>
<Field />
</ns:root>
版本 2
<ns:root ....>
<Field>Value</Field>
</ns:root>
我解决了。
;WITH XMLNAMESPACES ('uri' as ns)
UPDATE Document
SET
XMLdata.modify('
insert text{"New value"}
into (/ns:root/Field)[1]
')
WHERE
(XMLData.exist('(/ns:root/Field/text())[1]')=0)
AND condition;
;WITH XMLNAMESPACES ('uri' as ns)
UPDATE Document
SET
XMLdata.modify('
replace value of (/ns:root/Field/text())[1]
with "Replaced value"
')
WHERE condition;