I
Ian W.
Hello, I posted a few days ago and received help but I’m still having a
problem with the query I’m trying to run. I’m new to Access and if anyone
could help out I would really appreciate it. Please, any ideas or suggestions
would really help. Thanks.
I have two tables from which im trying to combine records: “LoadCons†and
“Landerâ€
I have 4 fields in each table.
They are: "Date", "ZipCode", "Weight", and "Cube"
I want to match on Date and Zip Code and sum at Weight and Cube for those
records that match.
For example:
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
I would want the query to return:
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 using this SQL which another user (Karl Dewey) helped me out with:
SELECT [LoadCons].KanePUDate, [LoadCons].[KaneZip],
Sum(nz([LoadCons].[KaneWgt])+nz([Lander].[LanderWgt])) AS [Total Weight],
Sum(nz([LoadCons].[KaneCube])+nz([Lander].[LanderCube])) AS [Total Cube]
FROM [LoadCons] INNER JOIN [Lander] ON ([LoadCons].[KaneZip] =
[Lander].[LanderZip]) AND ([LoadCons].KanePUDate = [Lander].[LanderPUDate])
GROUP BY [LoadCons].KanePUDate, [LoadCons].[KaneZip];
The problem is this:
When there are two records from LoadCons and one from Lander, the cube and
weight for LoadCons totals correctly, but the numbers double for
the Lander.
For example,
LoadCons
KanePUDate ___KaneZip___KaneWgt____KaneCube
1/1___________00001______3_________4
1/1___________00001______2_________1
1/2___________00002______6_________6
Lander
LanderPUDate ___LanderZip___LanderWgt____LanderCube
1/1______________00001_______2__________2
1/3______________00002_______4__________4
The query should return
KanePUDate ___KaneZip___Total Weight____Total Cube
1/1___________00001_______7___________7
(taking the first2 records from LoadCons and the first from Lander)
Instead it is returning:
KanePUDate ___KaneZip___Total Weight____Total Cube
1/1___________00001________9____________9
(taking the first 2 records from LoadCons, and doubling the first record from
Lander)
I thought this might be due to the "nz" function and I've tried running the
query without it but that yields no change.
Does anyone have any ideas as to why its doing this? Please, I’d really
appreciate any help or ideas anyone could offer. Thanks!
-Ian
problem with the query I’m trying to run. I’m new to Access and if anyone
could help out I would really appreciate it. Please, any ideas or suggestions
would really help. Thanks.
I have two tables from which im trying to combine records: “LoadCons†and
“Landerâ€
I have 4 fields in each table.
They are: "Date", "ZipCode", "Weight", and "Cube"
I want to match on Date and Zip Code and sum at Weight and Cube for those
records that match.
For example:
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
I would want the query to return:
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 using this SQL which another user (Karl Dewey) helped me out with:
SELECT [LoadCons].KanePUDate, [LoadCons].[KaneZip],
Sum(nz([LoadCons].[KaneWgt])+nz([Lander].[LanderWgt])) AS [Total Weight],
Sum(nz([LoadCons].[KaneCube])+nz([Lander].[LanderCube])) AS [Total Cube]
FROM [LoadCons] INNER JOIN [Lander] ON ([LoadCons].[KaneZip] =
[Lander].[LanderZip]) AND ([LoadCons].KanePUDate = [Lander].[LanderPUDate])
GROUP BY [LoadCons].KanePUDate, [LoadCons].[KaneZip];
The problem is this:
When there are two records from LoadCons and one from Lander, the cube and
weight for LoadCons totals correctly, but the numbers double for
the Lander.
For example,
LoadCons
KanePUDate ___KaneZip___KaneWgt____KaneCube
1/1___________00001______3_________4
1/1___________00001______2_________1
1/2___________00002______6_________6
Lander
LanderPUDate ___LanderZip___LanderWgt____LanderCube
1/1______________00001_______2__________2
1/3______________00002_______4__________4
The query should return
KanePUDate ___KaneZip___Total Weight____Total Cube
1/1___________00001_______7___________7
(taking the first2 records from LoadCons and the first from Lander)
Instead it is returning:
KanePUDate ___KaneZip___Total Weight____Total Cube
1/1___________00001________9____________9
(taking the first 2 records from LoadCons, and doubling the first record from
Lander)
I thought this might be due to the "nz" function and I've tried running the
query without it but that yields no change.
Does anyone have any ideas as to why its doing this? Please, I’d really
appreciate any help or ideas anyone could offer. Thanks!
-Ian