My mind has gone blank...I am missing something obvious trying to write a small script:
I have one table with various ID's:
TBL_USETHISID
nextid int
I have another table with references:
TBL_REFS
ref varchar(6)
thisdate datetime
nextid int
I want to take the ID from TBL_USETHISID and then update TBL_REFS so each row's ID is one more than the previous. I will then select the max(nextid) from TBL_REFS and update TBL_USETHISID with the highest.
I am struggling a bit with this, we have to use this instead of auto-incrememnt fields as these ID's are used across multiple tables.
Obviously I have tried:
UPDATE TBL_REFS FROM TBL_USETHISID
SET nextid = TBL_USETHISID.nextid + 1
Thanks for all your help in advance.
EDIT - Sample data:
TBLUSETHISID:
nextid
7001
TBL_REFS
ref thisdate nextid
0000123 2012-10-02 00:00:00
0000124 2012-10-02 00:00:00
0000125 2012-10-02 00:00:00
After update:
TBL_REFS
ref thisdate nextid
0000123 2012-10-02 00:00:00 7001
0000124 2012-10-02 00:00:00 7002
0000125 2012-10-02 00:00:00 7003
Then I would UPDATE TBL_USETHISID FROM TBL_REFS a set nextid = max(a.nextid)+1 to update the original table. I hope my formatting is correct, i idented like code for readability.