2
我有以下數據的XML列的值替換元素值:SQL Server中的XML-DML如何與相關的XPath
<Policy>
<Name>
<Id>adf</Id>
<First>Alan</First>
<Last>Turing</Last>
</Name>
<Name>
<Id>asdf</Id>
<Business>Vandelay Industries</Business>
</Name>
<Name>
<Id>asdf</Id>
<First>Dennis</First>
<Last>Ritchie</Last>
</Name>
</Policy>
我將如何編寫XML-DML查詢,將取代的價值所有行中每個Name的Id元素,因此它包含First,Last和Business的值。例如:
<Policy>
<Name>
<Id>AlanTuring</Id>
<First>Alan</First>
<Last>Turing</Last>
</Name>
<Name>
<Id>Vandelay Industries</Id>
<Business>Vandelay Industries</Business>
</Name>
<Name>
<Id>DennisRitchie</Id>
<First>Dennis</First>
<Last>Ritchie</Last>
</Name>
</Policy>
這裏是我的失敗嘗試:
update policy set data.modify('
replace value of (//Name/Id/text())[1]
with concat(
(//Name/First/text())[1],
(//Name/Last/text())[1],
(//Name/Business/text())[1])')
將會產生如下:
<Policy>
<Name>
<Id>AlanTuringVandelay Industries</Id>
<First>Alan</First>
<Last>Turing</Last>
</Name>
<Name>
<Id>asdf</Id>
<Business>Vandelay Industries</Business>
</Name>
<Name>
<Id>asdf</Id>
<First>Dennis</First>
<Last>Ritchie</Last>
</Name>
</Policy>