title: Compare two tables and Insert/Update data
body: <p>I have two tables as below what i need to do is 
  Loop through Table2 rows and need to check if table1ID in Table2 exists in table1. If exists update existing table1 row active flag to 0 and insert a new record in table1 with values from Table2 row. If does not exist insert a new record in table1 with values from Table2 row. We can assume E1, E2,E3 columns correspond to Q1A, Q2A, Q3A in table1.</p>
  
  <pre><code>Table1:
  Table1ID   Q1A    Q2A      Q3A    Active 
  1           2      Test     1       1
  2           3      Test2    1       1
  3           4      Test3    1       1
  4           5      Test4    1       1
  
  
  Table2:
  Table1ID   E1       E2          E3      
  1           2      TestData1     1       
  2           3      TestData2     1      
  3           4      TestData3     1      
  5           5      TestData5     1     
  6           7      TestData6     0
  </code></pre>