stephengrenfell
Registered User.
- Local time
- Today, 22:25
- Joined
- Jul 1, 2009
- Messages
- 19
I have an orders database in Access 2007 with several tables (tblCust, tblInv and tblInvDetail) containing customer information, order information and order details respectively. I want to add orders which are imported via a temporary table (Import_VmOrderListFile) using several queries.
The first query adds the customer details into tblCust from Import_VmOrderListFile if the customer number Import_VmOrderListFile.user_id does not exist in tblCust.CustNum .
If an order has multiple items then there is a row in Import_VmOrderListFile for each item on the order. I can’t change the format of the import table. Hence I do not want the query to add the customer details into tblCust more than once.
Below is the code for the query. However where there are multiple entries for an order in Import_VmOrderListFile the query tries to add the customer details into tblCust for each entry.
What am I doing wrong ?. Any help would be appreciated.
Thanks
INSERT INTO tblCust ( CustNum, CustLName, CustAddr1, CustAddr2, CustZip, CustCity, CustState, CustPhone, CustEmail, CustNote, LivLName, LivAddr1, LivAddr2, LivCity, LivZip, LivState, LivPhone )
SELECT DISTINCT Import_VmOrderListFile.user_id, Import_VmOrderListFile.BT_name, Import_VmOrderListFile.BT_address_1, Import_VmOrderListFile.BT_address_2, Import_VmOrderListFile.BT_zip, Import_VmOrderListFile.BT_city, Import_VmOrderListFile.BT_country, Import_VmOrderListFile.BT_phone_1, Import_VmOrderListFile.user_email, Import_VmOrderListFile.customer_note, Import_VmOrderListFile.ST_name, Import_VmOrderListFile.ST_address_1, Import_VmOrderListFile.ST_address_2, Import_VmOrderListFile.ST_city, Import_VmOrderListFile.ST_zip, Import_VmOrderListFile.ST_country, Import_VmOrderListFile.ST_phone_1
FROM Import_VmOrderListFile
WHERE Import_VmOrderListFile.user_id NOT IN (SELECT CustNum FROM tblCust);
The first query adds the customer details into tblCust from Import_VmOrderListFile if the customer number Import_VmOrderListFile.user_id does not exist in tblCust.CustNum .
If an order has multiple items then there is a row in Import_VmOrderListFile for each item on the order. I can’t change the format of the import table. Hence I do not want the query to add the customer details into tblCust more than once.
Below is the code for the query. However where there are multiple entries for an order in Import_VmOrderListFile the query tries to add the customer details into tblCust for each entry.
What am I doing wrong ?. Any help would be appreciated.
Thanks
INSERT INTO tblCust ( CustNum, CustLName, CustAddr1, CustAddr2, CustZip, CustCity, CustState, CustPhone, CustEmail, CustNote, LivLName, LivAddr1, LivAddr2, LivCity, LivZip, LivState, LivPhone )
SELECT DISTINCT Import_VmOrderListFile.user_id, Import_VmOrderListFile.BT_name, Import_VmOrderListFile.BT_address_1, Import_VmOrderListFile.BT_address_2, Import_VmOrderListFile.BT_zip, Import_VmOrderListFile.BT_city, Import_VmOrderListFile.BT_country, Import_VmOrderListFile.BT_phone_1, Import_VmOrderListFile.user_email, Import_VmOrderListFile.customer_note, Import_VmOrderListFile.ST_name, Import_VmOrderListFile.ST_address_1, Import_VmOrderListFile.ST_address_2, Import_VmOrderListFile.ST_city, Import_VmOrderListFile.ST_zip, Import_VmOrderListFile.ST_country, Import_VmOrderListFile.ST_phone_1
FROM Import_VmOrderListFile
WHERE Import_VmOrderListFile.user_id NOT IN (SELECT CustNum FROM tblCust);