title: Update top 50 rows from other table
body: <p>How can you get the top 50 rows from a table and update them into another table where the ID's (rows) may not already exist in the second, the 'to update', table?</p>
  
  <p>By Top 50 I mean the 50 locations (asc) that are not in the CycleCount table already, some background: I would like to store 50 locations (per update) in the table CycleCount. All the locations that exist, are populated in the table Warehouse. Everytime, I'd like to add 50 new locations from warehouse into cyclecount, but the updated locations need to be in ascending order (of warehouse location)</p>
  
  <p>I have tried using UPDATE TOP (50) Table1 SET ... etc. but that doesn't work in this case.</p>
  
  <p>I have this code, but this will update ALL locations (rows) instead of the top 50 (new) locations: </p>
  
  <pre><code>DECLARE @N INT 
  SET @N = 50
  UPDATE CycleCount
  SET MagLoc   = items.UserField_06, 
      Itemcode = items.ItemCode,
      CCDate   = GETDATE()
  FROM Warehouse LEFT OUTER JOIN items ON Warehouse.Location = items.UserField_06
  WHERE WareHouse.Location NOT IN (select MagLoc from CycleCount) 
  GO
  </code></pre>