I
Ian W.
Hello, any help or suggestions anyone could offer me with this would be
greatly appreciated.
Right now, I have a query that matches on Date and Zip Code and sums at
Weight and Cube for those records that match.
(Thanks to Karl Dewey and Kingingston via AccessMonster.com for helping me
out with that)
I want to figure out a way to match on date for plus or minus one day and
still match exactly on zip code, while still summing weight and cube.
I have two tables from which I’m trying to combine records: “LoadCons†and
“Landerâ€
I have 4 fields in each table.
They are: "Date", "ZipCode", "Weight", and "Cube"
This is what the query currently does:
If these were my tables:
LoadCons
KanePUDate ___KaneZip___KaneWgt____KaneCube
1/2___________00001______2__________3
1/2___________00002______3__________2
1/3___________00003______1__________2
1/3___________00004______2__________3
1/3___________00005______2__________1
Lander
LanderPUDate ___LanderZip___LanderWgt____LanderCube
1/2______________00006______2____________3
1/2______________00002______3____________2
1/3______________00003______1____________2
1/3______________00007______2____________3
1/3______________00008______2____________1
The query returns:
KanePUDate ___KaneZip___Total Weight____Total Cube
1/2___________00002________6___________4
(combined the 2nd record from each table)
1/3___________00003________2___________4
(combined the 3nd record from each table)
I’m achieving this by running totals queries on each table first, grouping
by date and zip and summing weight and cube. I then used the make table query
to put the results into tables. I then ran a totals query where I joined the
fields on date and zip for the 2 newly created tables and summed weight and
cube.
Here is the SQL:
FOR THE LOADCONS TABLE:
SELECT LoadCons.KaneZip, LoadCons.KanePUDate, Sum(LoadCons.KaneCube) AS
SumOfKaneCube, Sum(LoadCons.KaneWgt) AS SumOfKaneWgt
FROM LoadCons
GROUP BY LoadCons.KaneZip, LoadCons.KanePUDate;
This created a new table “LoadConscomâ€
FOR THE LANDER TABLE:
SELECT Lander.LanderZip, Lander.LanderPUDate, Sum(Lander.LanderWgt) AS
SumOfLanderWgt, Sum(Lander.LanderCube) AS SumOfLanderCube
FROM Lander
GROUP BY Lander.LanderZip, Lander.LanderPUDate;
This created a new table “Landercomâ€
I THEN JOINED THE 2 NEW TABLES, “LoadConscom†and “Landercomâ€:
SELECT LoadConscom.KanePUDate, LoadConscom.KaneZip,
Sum(nz(LoadConscom.SumOfKaneWgt)+nz(Landercom.SumOfLanderWgt)) AS [Total
Weight], Sum(nz(LoadConscom.SumOfKaneCube)+nz(Landercom.SumOfLanderCube)) AS
[Total Cube]
FROM LoadConscom INNER JOIN Landercom ON
(LoadConscom.KaneZip=Landercom.LanderZip) AND
(LoadConscom.KanePUDate=Landercom.LanderPUDate)
GROUP BY LoadConscom.KanePUDate, LoadConscom.KaneZip;
Does anyone know a way I could do this same query but match dates not only
for exact day, but also on plus or minus a day? I still need zip code to
match exactly and sum the weight and cube fields for records combined.
Please post if you have any suggestions. I’ve tried fooling around with
different criteria but with no success. I’d really appreciate any help you
could offer. Thank You!
-Ian
greatly appreciated.
Right now, I have a query that matches on Date and Zip Code and sums at
Weight and Cube for those records that match.
(Thanks to Karl Dewey and Kingingston via AccessMonster.com for helping me
out with that)
I want to figure out a way to match on date for plus or minus one day and
still match exactly on zip code, while still summing weight and cube.
I have two tables from which I’m trying to combine records: “LoadCons†and
“Landerâ€
I have 4 fields in each table.
They are: "Date", "ZipCode", "Weight", and "Cube"
This is what the query currently does:
If these were my tables:
LoadCons
KanePUDate ___KaneZip___KaneWgt____KaneCube
1/2___________00001______2__________3
1/2___________00002______3__________2
1/3___________00003______1__________2
1/3___________00004______2__________3
1/3___________00005______2__________1
Lander
LanderPUDate ___LanderZip___LanderWgt____LanderCube
1/2______________00006______2____________3
1/2______________00002______3____________2
1/3______________00003______1____________2
1/3______________00007______2____________3
1/3______________00008______2____________1
The query returns:
KanePUDate ___KaneZip___Total Weight____Total Cube
1/2___________00002________6___________4
(combined the 2nd record from each table)
1/3___________00003________2___________4
(combined the 3nd record from each table)
I’m achieving this by running totals queries on each table first, grouping
by date and zip and summing weight and cube. I then used the make table query
to put the results into tables. I then ran a totals query where I joined the
fields on date and zip for the 2 newly created tables and summed weight and
cube.
Here is the SQL:
FOR THE LOADCONS TABLE:
SELECT LoadCons.KaneZip, LoadCons.KanePUDate, Sum(LoadCons.KaneCube) AS
SumOfKaneCube, Sum(LoadCons.KaneWgt) AS SumOfKaneWgt
FROM LoadCons
GROUP BY LoadCons.KaneZip, LoadCons.KanePUDate;
This created a new table “LoadConscomâ€
FOR THE LANDER TABLE:
SELECT Lander.LanderZip, Lander.LanderPUDate, Sum(Lander.LanderWgt) AS
SumOfLanderWgt, Sum(Lander.LanderCube) AS SumOfLanderCube
FROM Lander
GROUP BY Lander.LanderZip, Lander.LanderPUDate;
This created a new table “Landercomâ€
I THEN JOINED THE 2 NEW TABLES, “LoadConscom†and “Landercomâ€:
SELECT LoadConscom.KanePUDate, LoadConscom.KaneZip,
Sum(nz(LoadConscom.SumOfKaneWgt)+nz(Landercom.SumOfLanderWgt)) AS [Total
Weight], Sum(nz(LoadConscom.SumOfKaneCube)+nz(Landercom.SumOfLanderCube)) AS
[Total Cube]
FROM LoadConscom INNER JOIN Landercom ON
(LoadConscom.KaneZip=Landercom.LanderZip) AND
(LoadConscom.KanePUDate=Landercom.LanderPUDate)
GROUP BY LoadConscom.KanePUDate, LoadConscom.KaneZip;
Does anyone know a way I could do this same query but match dates not only
for exact day, but also on plus or minus a day? I still need zip code to
match exactly and sum the weight and cube fields for records combined.
Please post if you have any suggestions. I’ve tried fooling around with
different criteria but with no success. I’d really appreciate any help you
could offer. Thank You!
-Ian