Hello, I'm not sure if this has been asked here before (wouldn't know what to search for).
Here's my situation...
I have records in Table1 that I need to insert into Table2.
However, there is a field in Table2 that is sequential (like an index) that I need to maintain...
Therefore I would need my query to lookup the max value for that index, then add one for each new record added from Table1
Illustration
Table1:
ID
5
6
7
8
Table2:
ID-------TranKey
1 56000
2 56001
3 56002
4 56003
I need to insert the records from Table1 into Table2 (based on ID), and then have TranKey remain sequential...
Table2:
ID-------TranKey
1 56001
2 56002
3 56003
4 56004
5 56005
6 56006
7 56007
8 56008
I would imagine I'd have to use the MAX function to determine the last used value for TranKey in Table2, and a WHILE loop to insert the records... but I'm not sure how to implement everything into one procedure.
Can anyone help me?
Any assistance would be greatly appreciated!
Here's my situation...
I have records in Table1 that I need to insert into Table2.
However, there is a field in Table2 that is sequential (like an index) that I need to maintain...
Therefore I would need my query to lookup the max value for that index, then add one for each new record added from Table1
Illustration
Table1:
ID
5
6
7
8
Table2:
ID-------TranKey
1 56000
2 56001
3 56002
4 56003
I need to insert the records from Table1 into Table2 (based on ID), and then have TranKey remain sequential...
Table2:
ID-------TranKey
1 56001
2 56002
3 56003
4 56004
5 56005
6 56006
7 56007
8 56008
I would imagine I'd have to use the MAX function to determine the last used value for TranKey in Table2, and a WHILE loop to insert the records... but I'm not sure how to implement everything into one procedure.
Can anyone help me?
Any assistance would be greatly appreciated!
Comment