title: How to create a query that gets only data which has been updated in a table
body: <p>I have no idea where to start or how this will work and I am hoping someone has an idea or a proven method.</p>
  
  <p>To show an example of what I am trying to do, I created a stored procedure which UPDATES or INSERT new records in a Local table by getting records from a link table. The Stored procedure runs as a Job in SQL Server to update and insert new records.</p>
  
  <p>My question is: Is there a way to query the data in the Local Table so That initially I can get all the records but than get only new records that has been inserted or old records that are updated?</p>
  
  <p>I do not want to continuously get all the records, just the new records added or the records updated.</p>
  
  <p>Is this possible?</p>
  
  <p>Here is the stored procedure I ave created as an example to updated the Local Phone data:</p>
  
  <pre><code>CREATE PROCEDURE sp_UPDATE_PHONE_RECORDS
  AS 
  BEGIN
  MERGE dbo.PHONE_REC AS Target
  USING (SELECT MEMBER_ID 
        ,HOME_PHONE = dbo.udf_StdPhoneFmt(HOME)
        ,CELL_PHONE = dbo.udf_StdPhoneFmt(CELL)
        ,WORK_PHONE = dbo.udf_StdPhoneFmt(WORK)
  
  FROM PHONE WHERE MEMBER_ID IS NOT NULL) AS SOURCE
  
  ON (Target.MEMBER_ID = SOURCE.MEMBER_ID)
  
  WHEN MATCHED THEN
  
      UPDATE SET Target.HOME_PHONE = Source.HOME_PHONE,Target.CELL_PHONE = Source.CELL_PHONE,
      Target.WORK_PHONE = Source.WORK_PHONE
  
  WHEN NOT MATCHED BY TARGET THEN
      INSERT (MEMBER_ID, HOME_PHONE, CELL_PHONE ,WORK_PHONE)
  
      VALUES (Source.MEMBER_ID, Source.HOME_PHONE, Source.CELL_PHONE, Source.WORK_PHONE);
  END
  GO
  </code></pre>
  
  <p>Is this possible?</p>
  
  <p>Thanks everyone!</p>