mardi 11 août 2015

Copy Data and increment PK in destination table

I have a temp table with data that needs to be split into 3 other tables. Each of those tables has a primary key that is not shared with each other or with the temp table. Here is a small sampling:

Table 1

RSN     AGENT   STATUS  STATUS DECRIPTION
0   280151  51  Terminated
1   86  57  C/O Comp Agent Dele
2   94  57  C/O Comp Agent Dele
3   108 51  Terminated

Table 2

RSN     AGENT   CITY
1   10  Englewood
2   123 Jackson
3   35  Eatontown
4   86  Trenton

Table 3

RSN     AGT     SIGN    NO_EMP  START_DATE
0   241008  Y   1   2002-10-31 00:00:00.000
1   86  Y   0   2002-10-24 09:51:10.247
2   94  Y   0   2002-10-24 09:51:10.247
3   108 Y   0   2002-10-24 09:51:10.247

I need to check each table to see if the data in the temp table exists and if it does not I want to insert those rows with a RSN# starting with the max number in that table. So if I have 5000 records in the first table and I am adding 5000 new rows they will be numbered 5001 through 10000.

I then need to check to see if any columns have changed for matching rows and update them.

Thanks in advance for your assistance.

Scott

Aucun commentaire:

Enregistrer un commentaire