I don't know exactly where to post this. Can it be done with a query? Does it need to be done through VBA? I'm not sure.
My database imports a production order from our production planning software. It's a simple import that brings in production number, product code and quantity required. The table has a primary key for each record which links to another table that stores information about quantity used and other tracking information we need.
So we might have a table with the following structure:
PK PRODUCTION # PRODUCT CODE QTY 100 123456 WIDGET_A 50 101 123456 WIDGET_B 25 101 123456 WIDGET_C 75
Everything works great. But I've been told that at times we will adjust the production order. Originally I thought that I could just delete the existing data, and re-import the new production information. However, this will delete all of the transactional data that links to the PK in this table. The main change is usually in the quantity of the raw materials. But they may also change some of the actual raw materials. So here's what I need to try to do:
Compare all of the products in my db versus our production planning db. If there is a difference in quantity, update the quantity to the amount in our production planning db. If a raw material in my db doesn't exist in the production planning db, delete it from my db. If a raw material exists in the production planning db and not in mine, import it to my db. This way we preserve the transactional data for the raw materials which haven't changed and update the production order on my db with all the correct raw materials and quantities.
This seems really complicated. Any idea how to go about doing this?