Refresh XML column of table in SQL Server 2008R2

I have a table named DateRule in sql server 2008R2 and I am trying to update the value of an XML column but it is not working as expected.

  • DateRuleId: 40
  • Description: 2 months after the launch date.
  • DateRuleXml:

            <Daterule>
                <Type>Timespan</Type>
                <months>2</months>
                <days>0</days>
                <hours>0</hours>
                <minutes>0</minutes>
                <seconds>0</seconds>
                <After>1</After>
                <Reference>1</Reference>
            </Daterule> 
    
          

I am trying to run the following query:

update centralq3.wf.DateRule
set DateRuleXml.modify('replace value of (/Daterule/@Reference)[1] with "6"')
where DateRuleId = 40

      

AND:

update centralq3.wf.DateRule
set DateRuleXml.modify('replace value of (//@Reference)[1] with "6"')
where DateRuleId = 40

      

They both succeeded and said (1 line (s) affected) but the Reference value does not change. What am I doing wrong? I know there are many questions regarding this but did not help me.

Change !! Answer:

UPDATE centralq3.wf.DateRule
SET DateRuleXml.modify('replace value of (/Daterule/Reference[1]/text())[1] with "6"')
WHERE DateRuleId = 40

      

+3


source to share


1 answer


He will:



SET DateRuleXml.modify('replace value of (/Daterule/Reference[1]/text())[1] with "6"');

      

0


source







All Articles