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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update table from two subquery

Status
Not open for further replies.

Goondu

Technical User
Jan 14, 2004
92
SG
Hi,

If anyone could help me with the correct SQL syntax for Updating a table.

Here’s the code.
Code:
UPDATE Table1 INNER JOIN Table2 ON Table1.ItemNo = Table2.ItemNo
SET Table1.QtyBal = (subquery1 – subquery2)

The two subqueries are

Select Sum([Qty]) From Table2 Where IssueDate Between #01-Jan-01# and #30-Jan-01#

Select Sum([Qty]) From Table2 Where IssueDate Between #15-Jan-01# and #30-Jan-01#

Thanks
 
You may consider the DSum function.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks for the suggestion PHV.
This may work with the VBA part but do you have any solution for a standard access query? I can't get the SQL syntax right.

Code:
UPDATE Table1 INNER JOIN Table2 ON Table1.ItemNo = Table2.ItemNo SET Table1.QtyBal = DSum("Qty","Table2","IssueDate Between " & "#1-jan-01#" & "  And " & "#15-jan-01#")-DSum("Qty","Table2","IssueDate Between " & "#16-jan-01#" & " And " & "#30-jan-01#");

Leslie, Table1.QtyBal is a temporary table for a report where all calculated values are stored.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top