title: SQL Server : setting flag in original table to processed after copying data
body: <p>I have a large table where I want to take the data from that table, and insert it into other (smaller) tables. But when doing this, I want to mark a column in the large table ("Processed") to true, so that the next time the query is run, it will not end up creating duplicates. Is there an easier way of doing this, other than creating the small query after-the-fact to set everything that is 0 to 1?  Or is this the most efficient way?</p>
  
  <pre><code>DECLARE @largeTable TABLE(
      [Id] [int] IDENTITY(1,1) NOT NULL,
      productName varchar(100),
      productId int,
      quantity int,
      someVar int,
      Processed bit)
  
  INSERT INTO @largeTable (productName, productId, quantity, someVar, Processed)
  VALUES ('Apple', 1, 50, 34, 0),
          ('Orange', 2, 50, 53, 0),
          ('Banana', 3, 50, 165, 0),
          ('Pineapple', 4, 74, 34, 0),
      ('Mango', 5, 50, 388, 0),
          ('Kiwi', 6, 50, 2, 0),
          ('Strawberry', 7, 50, 16, 0)
  
  SELECT * FROM @largeTable
  
  DECLARE @smallTable TABLE(
      [Id] [int] IDENTITY(1,1) NOT NULL,
      productName varchar(100),
      productId int)
  
  INSERT INTO @smallTable (productName, productId)
  SELECT productName, productId
  FROM @largeTable
  WHERE Processed = 0
  
  UPDATE @largeTable
  Set Processed = 1
  WHERE Processed = 0
  
  SELECT * FROM @largeTable
  SELECT * FROM @smallTable
  </code></pre>