title: SQL Server - Update data
body: <p>I have an table with this structure (example) <strong>ORIGNTABLE</strong>:</p>
  
  <pre><code>ID    IDParent
  80       0
  81       80
  82       0
  83       82
  </code></pre>
  
  <p>Then I make a duplicate of this data obtaining the following data:</p>
  
  <pre><code>ID    IDParent
  80       0
  81       80
  82       0
  83       82
  ---- duplicated data ---
  84       0
  85       80
  86       0
  87       82
  </code></pre>
  
  <p>on the other hand, with the duplication of data also get a temporary table with the following information  <strong>AUXTABLE</strong>:</p>
  
  <pre><code>OldID   NewID   OldParentID
  80      84      0
  81      85      80
  82      86      0
  83      87      82
  </code></pre>
  
  <p>So, my problem is update the new data, specifically, the IDParent. I'm failing to do this.
  I pretend the final data like that:</p>
  
  <pre><code>ID    IDParent
  80       0
  81       80
  82       0
  83       82
  ---- duplicated data ---
  84       0
  85       **84**
  86       0
  87       **86**
  </code></pre>
  
  <p>Anyone can help me to update the data? i'm trying many options but none work:
  <em>1st try</em></p>
  
  <pre><code>UPDATE ORIGINTABLE
  SET IDParent = AT.NewID
  FROM ORIGINTABLE OT 
  INNER JOIN AUXTABLE AT ON AT.NewID=OT.ID
  AND AT.OldParentID=OT.IDParent
  </code></pre>
  
  <p><em>2st try</em></p>
  
  <pre><code> UPDATE ORIGINTABLE
      SET IDParent =AT.NewID
      FROM ORIGINTABLE OT 
      INNER JOIN AUXTABLE AT ON AT.OldParentID=OT.ID
  </code></pre>