0

I am trying to modify the node in the XML that it gets a new id after inserting in the main XML this xmlfields where groupid = @groupid element and the qubefieldId = @i

Can someone tell me why this is not working?

Update @temp
Set xmlField.modify('replace value of (/ArrayOfQubeField/QubeField[QubeFieldID = sql:variable("@i")]/text())[1] with sql:variable  ("@newID")')
Where XmlField.exist('/ArrayOfQubeField/QubeField[GroupID = sql:variable ("@groupID")][QubeFieldID = sql:variable("@i")]') = 1;

Here is the xml

<ArrayOfQubeField xmlns:xsi="http://www.w3.org/2001/XMLSchema-   instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <QubeField>
      <QubeFieldID>1</QubeFieldID>
      <GroupID>1</GroupID>
      <QubeFieldName>ID</QubeFieldName>
      <QubeFieldSelected>true</QubeFieldSelected>
      <Order>0</Order>
  </QubeField>
 <QubeField>
 <QubeFieldID>1</QubeFieldID>
     <GroupID>4</GroupID>
     <QubeFieldName>Name</QubeFieldName>
     <QubeFieldSelected>true</QubeFieldSelected>
     <Order>1</Order>
 </QubeField>
 <QubeField>
    <QubeFieldID>2</QubeFieldID>
    <GroupID>3</GroupID>
    <QubeFieldName>Town</QubeFieldName>
    <QubeFieldSelected>true</QubeFieldSelected>
    <Order>2</Order>
 </QubeField>
 <QubeField>
    <QubeFieldID>1</QubeFieldID>
    <GroupID>3</GroupID>
    <QubeFieldName> Name</QubeFieldName>
    <QubeFieldSelected>true</QubeFieldSelected>
    <Order>3</Order>
 </QubeField>
 <QubeField>
    <QubeFieldID>13</QubeFieldID>
    <GroupID>1</GroupID>
    <QubeFieldName>Migrated</QubeFieldName>
    <QubeFieldSelected>true</QubeFieldSelected>
    <Order>4</Order>
 </QubeField>
 <QubeField>
   <QubeFieldID>16</QubeFieldID>
   <GroupID>1</GroupID>
   <QubeFieldName>Date</QubeFieldName>
   <QubeFieldSelected>true</QubeFieldSelected>
   <Order>5</Order>
 </QubeField>
</ArrayOfQubeField>
6
  • @marc_s Why knock me down Commented Mar 26, 2015 at 15:28
  • I only tried to clean up your post a bit - I DID NOT downvote you! Commented Mar 26, 2015 at 16:04
  • 1
    If I'd have to guess I would say you got a downvote because your question is quite unclear. "Not working" is not a error description - What does not work, what message do you get? Also, screaming "URGENT" at as in the title will not make any of us answer faster (in our free time; for free) Commented Mar 26, 2015 at 18:07
  • @marc_s sorry thought you had I do appologise Commented Mar 26, 2015 at 20:16
  • I only put urgent on it because it is, The xpath does not update the id as I put in the description the piece of code should by logic up date the value of the node text. Commented Mar 26, 2015 at 20:18

1 Answer 1

1

You're missing QubeFieldID in the XPath, try something like this:

update @temp set
    xmlField.modify('
        replace value of
        (/ArrayOfQubeField/QubeField[GroupID = sql:variable ("@groupID")]/QubeFieldID[. = sql:variable("@i")]/text())[1]
        with sql:variable("@newID")
    ')

sql fiddle demo

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you I had not done what you did but mine was bit fiddler by using the position and another loop by using a count. I will change my code to yours its much neater.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.