这是我在表字段中的 XML
<CtcConfiguration xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Ctc>3</Ctc>
<SalaryComponent>
<SalaryComponentConfiguration>
<Name>Basic</Name>
<DisplayOrder>0</DisplayOrder>
<Value>5634655</Value>
</SalaryComponentConfiguration>
<SalaryComponentConfiguration>
<Name>HR</Name>
<DisplayOrder>0</DisplayOrder>
<Value>1234</Value>
</SalaryComponentConfiguration>
<SalaryComponentConfiguration>
<Name>medical</Name>
<DisplayOrder>0</DisplayOrder>
<Value>0</Value>
</SalaryComponentConfiguration>
</SalaryComponent>
</CtcConfiguration>
我希望node(DisplayOrder)
根据node(Name)
. 例如,如果我将名称命名为医疗,它应该根据需要更新displayorder值。
这是我到目前为止所尝试的:
UPDATE payroll.pays set
CtcConfiguration.modify('replace value of (/CtcConfiguration/SalaryComponent/SalaryComponentConfiguration/DisplayOrder/text())[1] with ("99999")')
where
CtcConfiguration.value('((/CtcConfiguration/SalaryComponent/SalaryComponentConfiguration/Name)[]/text())[1]','varchar(50)') = 'HR'