title: SQL: Export data to new table and update old data simultaneously
body: <p>I want to export data from one table into a new one with a nightly job.</p>
  
  <p>To prevent generate dublicates, I implemented a column named "ExportState" in the source table which is 0 for not exported and 1 for exported.</p>
  
  <p>My problem is, that I want to export the data and then setting the State to 1. But I can not make a <code>INSERT INTO ... SELECT</code> and then UPDATE Statements because it is possible that additional Data would inserted to the source table while the export routine runs. So I would at the end UPDATE the ExportState to 1 on records which I never INSERTed to the destination table.</p>
  
  <p>Do you have suggestions to the following solutions ?</p>
  
  <p>A. <code>INSERT INTO ... SELECT</code> and <code>UPDATE</code> ExportState row by row<br>
  B. Take a Snaphot <code>INSERT</code> and <code>UPDATE</code> ExportState of the snapshoted Data</p>
  
  <p>Which makes more sense ?</p>
  
  <p>The second problem: The source and destination tables are on different SQL Servers and database instances. Ideas ?</p>