title: T-SQL For Each Alternative?
body: <p>I need to take data from one table and import it into another table. In pseudocode, something like this:</p>
  
  <pre><code>For Each row in table1
  If row.personid is in table2 then
     update table2.row
  Else
     insert row into table2
  End If
  Next
  </code></pre>
  
  <p>What is the best way to do this in T-SQL? As I understand it T-SQL doesn't support For Each..Next, so what alternatives do I have?</p>