Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Appending Tables

Status
Not open for further replies.

Work23

Technical User
Joined
Mar 8, 2005
Messages
94
Location
US
Hello. I need to append a table that is a copy of another table. There will be ID numbers appended or updated to this table every hour or so. The ID number is set to a primary key. How would I overlap that data without gettin a primary key error while being able to append the data? Please let me know if you need more information. Thanks so much. Take care.
 
I'm not quite sure this is what you are looking for, but...maybe something like

Code:
INSERT INTO table_copy
  SELECT *
  FROM table_original
  WHERE IDnbr > (SELECT MAX(IDnbr) FROM table_copy)

-SQLBill



Posting advice: FAQ481-4875
 
This is def what I would need to do. I"m just a bit confused on how to make this work the first time it is run. Because, Table_copy contains nothing, the first time it is run. It is populated on the first run, then I need to do the code you wrote above. How would I get both aspects together, so I wouldn't have to change the code after it is run the first time to populate the Table_copy?
 
Then it will get a NULL for the IDnbr from Table_copy and INSERT everything from Table_original.

-SQLBill

Posting advice: FAQ481-4875
 
I'm sorry, I don't think I understand. I will get a NULL for IDnbr in table_copy which is empty the first time the program is ran based on this code?:

INSERT INTO table_copy
SELECT *
FROM table_original
WHERE IDnbr > (SELECT MAX(IDnbr) FROM table_copy)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top