当前位置: 代码迷 >> Sql Server >> 怎么替换xml类型字段的多个属性值
  详细解决方案

怎么替换xml类型字段的多个属性值

热度:12   发布时间:2016-04-27 11:16:31.0
如何替换xml类型字段的多个属性值

SQL code
 
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 ([email protected])[1]
  with    "100.0"
')
SELECT @myDoc



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

我说过写多条 replace value of (...) with "" 不行。

------解决方案--------------------
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 ([email protected])[1]
with "100.0"
')
SET @myDoc.modify('
replace value of ([email protected])[1]
with "100.0"
')

SELECT @myDoc
  相关解决方案