February 12, 2007 at 9:52 am
Hi everyone,
got a bit of an issue I hope someone can offer some advice on.
Overview.
Previously I used the attached code to import data into another table using a table (NewPrice List) that contained the new values. When I did this it was an overwrite of existing data , i.e. the itemcode value existed in the table I was trying to overwrite with new values.
Code:
UPDATE MATBIT INNER JOIN [NewPrice List] ON MATBIT.ITEMCODE=[NewPrice List].ITEMCODE SET MATBIT.PRICE = [NewPrice List]!MATBITPRICE, MATBIT.DESC_Col = [NewPrice List]!MATBITDESC_COL;
Now however situatuation is different in that the NewPrice List table contains new values , i.e. not over writting any existing values but creating new ones.
Any offer some advice on how to change the above to allow new values to be inserted.
Many thanks for any advice
February 12, 2007 at 10:24 am
/*updating existing values*/
UPDATE MATBIT INNER JOIN [NewPrice List] ON MATBIT.ITEMCODE=[NewPrice List].ITEMCODE SET MATBIT.PRICE = [NewPrice List]!MATBITPRICE, MATBIT.DESC_Col = [NewPrice List]!MATBITDESC_COL;
/*inserting new values*/
INSERT INTO MATBIT
(PRICE,DESC_Col,ITEMCODE )
SELECT NoSpaces.MATBITPRICE,...
FROM [NewPrice List] NoSpaces
WHERE NOT EXISTS
(SELECT * FROM MATBIT WHERE MATBIT.ITEMCODE=NoSpaces.ITEMCODE)
February 13, 2007 at 12:59 am
Jo
Many thanks for this , when I try to run the code from /*inserting new values*/ I get an error.
Syntax error. (Missing operator) in query expression '...'.
Trying to run this is Access at the moment , don't know if that has a change on the code needed ?
Thanks for your help.
February 13, 2007 at 3:25 am
El,
The ... was "and so on". The left join causes MATBIT.ITEMCODE to be null if NoSpaces.ITEMCODE isn't found in MATBIT. Actual syntax can differ bases on Access version and how you connect to your database (linked tables, oledb,odbc)
INSERT INTO MATBIT
(PRICE,DESC_Col,ITEMCODE )
SELECT NoSpaces.MATBITPRICE,NoSpaces.MATBITDESC_COL,NoSpaces.ITEMCODE
FROM [NewPrice List] NoSpaces
LEFT JOIN MATBIT
ON MATBIT.ITEMCODE=NoSpaces.ITEMCODE
WHERE MATBIT.ITEMCODE IS NULL
February 13, 2007 at 3:45 am
Jo
Many thanks for your help , that has worked a treat. Now have to understand fully what is going on.
Many thanks once again
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply