核心提示:*我在VB 里用SQL 进行UPDATE 时, 如果XML里的某个属性为空就无法UPDATEreplace value of XML DML 语句以下示例说明如何在 XML 文档中更新节点。在以下示例...
*我在VB 里用SQL 进行UPDATE 时, 如果XML里的某个属性为空就无法UPDATE
replace value of XML DML 语句以下示例说明如何在 XML 文档中更新节点。
在以下示例中,首先将文档实例分配给 xml 类型的变量。然后,replace value of XML DML 语句将更新文档中的值。
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 text in the first manufacturing step
SET @myDoc.modify('
replace value of (/Root/Location/step[1]/text())[1]
with "new text describing the manu step"
')
SELECT @myDoc
-- update attribute value
SET @myDoc.modify('
replace value of (/Root/Location/@LaborHours)[1]
with "100.0"
')
SELECT @myDoc


