使用SQL Server中的单个更新更新多个XML列

时间:2018-03-19 20:10:11

标签: sql-server xml

我想使用第二个table_A的(AcresDist1,txtAcresDist1,txtAcresDist1Total)XML列的新值更新table_B

P_XML属于XML类型。我知道如何一次更新单个列,但我想知道如何使用单个更新语句更新XML中的多个列。谢谢

SQL代码:

UPDATE S
SET
   P_XML.modify( N'replace value of (/FormValue/f1152_F1/Field[(id/text())[1]="AcresDist1"]/value/text())[1] with sql:column(''T.AcresDist1'')' )
 , P_XML.modify( N'replace value of (/FormValue/f1152_F1/Field[(id/text())[1]="txtAcresDist1"]/value/text())[1] with sql:column(''T.txtAcresDist'')' )
 , P_XML.modify( N'replace value of (/FormValue/f1152_F1/Field[(id/text())[1]="txtAcresDist1Total"]/value/text())[1] with sql:column(''T.txtAcresDist1Total'')' )
FROM   
    Table_A AS S
INNER JOIN 
    Table_B AS T ON s.P_NO = t.P_Number
                 AND s.FAC_RID = t.Fac_RID;

以下是请求的示例xml。谢谢。

<FormValue>
  <f1152>
<field>
  <id>f1152_MainForm</id>
  <value />
  <tag />
  <visible>true</visible>
  <history>|09/28/2017 10:50:26 AM||</history>
  <description />
  <comment />
</field>
<field>
  <id>txt_rdoCoverage</id>
  <value>Development</value>
  <tag />
  <visible>false</visible>
  <history>|09/28/2017 10:50:26 AM||</history>
  <description />
  <comment />
</field>
</f1152>
<f1152_F1>
<field>
 <id>txtAcresDist1</id>
  <value>1.2</value>
  <tag />
  <visible>false</visible>
  <history>|09/28/2017 3:08:14 AM||</history>
  <description />
  <comment />
</field>
<field>
  <id>txtAcresDist1Total</id>
  <value>200</value>
  <tag />
  <visible>false</visible>
  <history>|09/28/2017 3:08:14 AM||</history>
  <description />
  <comment />
</field>
</f1152_F1>

0 个答案:

没有答案