如何替换xml类型字段的多个属性值

gungod 2012-07-16 03:05:31


DECLARE @myDoc xml
SET @myDoc = '<Root>
<Location LocationID="10"
LaborHours="1.1"
MachineHours=".2" >Manufacturing steps are described here.
<step>Manufacturing step 1 at this work center</step>
<step>Manufacturing step 2 at this work center</step>
</Location>
</Root>'
SELECT @myDoc
-- update attribute value
SET @myDoc.modify('
replace value of (/Root/Location/@LaborHours)[1]
with "100.0"
')
SELECT @myDoc



查MSDN知道,replace value of ...可以用来替换xml类型的值,
示例也是摘抄MSDN的,如果要在一条sql里完成对LocationID,LaborHours,MachineHours属性的修改,应该怎么做?

我说过写多条 replace value of (...) with "" 不行。
...全文
180 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
gungod 2012-09-03
  • 打赏
  • 举报
回复
没满意答案结贴把。
gungod 2012-08-30
  • 打赏
  • 举报
回复
这里也是分2次啊。。。。
quchen520 2012-07-16
  • 打赏
  • 举报
回复
DECLARE @myDoc xml
SET @myDoc = '<Root>
<Location LocationID="10"
LaborHours="1.1"
MachineHours=".2" >Manufacturing steps are described here.
<step>Manufacturing step 1 at this work center</step>
<step>Manufacturing step 2 at this work center</step>
</Location>
</Root>'
SELECT @myDoc
-- update attribute value
SET @myDoc.modify('
replace value of (/Root/Location/@LaborHours)[1]
with "100.0"
')
SET @myDoc.modify('
replace value of (/Root/Location/@MachineHours)[1]
with "100.0"
')

SELECT @myDoc

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧