【问题标题】:Modifying SQL XML column修改 SQL XML 列
【发布时间】:2010-06-15 08:46:45
【问题描述】:

我的一张表中有一个 XML 列。例如,我有一个包含以下字段的 Employee 表:

Name (varhcar) | Address (XML)

地址字段的值类似于

<Address>
<Street></Street>
<City></City>
</Address>

我的表中已有 n 行。 现在我想向表中的所有行插入一个新节点 - Country。默认情况下:

<Country>IND</Country>.

我该如何为此编写查询。我希望所有现有数据都与将国家节点添加到所有地址列 XML 一样。

【问题讨论】:

  • 要显示您的 XML,您需要将其格式化为代码。我已经为你做了这个......

标签: xml sql-server-2005


【解决方案1】:
update Employee set Address.modify('insert  <Country>IND</Country>
 as last into (/Address)[1]')

【讨论】:

    【解决方案2】:

    试试这个

    SET @XMLDATA.modify(' insert <Country>IND</Country> as last into (Address[1]) ')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-11
      • 2023-03-02
      • 2019-05-25
      • 1970-01-01
      相关资源
      最近更新 更多