Insert Update Or Append Table

toqilula

Registered User.
Local time
Today, 11:46
Joined
Dec 13, 2009
Messages
24
Greetings,

I'm trying to update values of one table from another table by adding to existing values.
I have two table , tbl1 and tbl2
in tbl1 i have items and qty same in tbl2 items and qty
now i would like to update tbl1.qty using RunSql with data from tbl2.qty
so if in tbl1.qty = 5, by clicking on the button I would like to add values from tbl2 (if tbl2.qty = 3 ) so i have tbl1.qty = 8
I would really appreciate if since im really running out of the opitions here.

P.S. i used SQL 2010 and this worked there but not in ms Access vba
DoCmd.RunSQL "UPDATE tbl1 SET tbl1.[Qty] = (SELECT (tbl1.[Qty] + tbl2.[Qty]) As total FROM tbl1 AS t1 INNER JOIN tbl2 AS t2 ON t1.[ID] = t2.[ID] WHERE t1.[ID] = tbl1.[ID])"

thank you in advanced
Best Regards
 
yeeeeeee
I found the solution.

UPDATE tbl1LEFT JOIN tbl2ON tbl1.ID = tbl2.ID SET tbl2.Qty = [tbl2].[Qty] + [tbl1].[Qty];

works like charm
I love you all

regards

P.S. Guess I'll get some sleep tonight afterall :)
 

Users who are viewing this thread

Back
Top Bottom