it's a hard one to explain....
There is no connection between the Qty columns in Table B and C. I have
trying to create an output that groups all the detail rows from Table B and C
by their common part number. If Part has 2 rows of data on Table B (Show
those 2 values) and if that same Part has 3 rows of data on Table C (Show
those 3 values). So that in the end I have an output of 3 rows of data from
that Part, ColumnA = Part Number, ColumnB = show the first 2 rows populated
from Table B and the 3 row Column B is blank, ColumnC = shows data in all 3
rows populated from Table C.
Not sure if I am making it more complicated that I need to, but this is what
I am trying to work through.
Thanks,
D
SQL:
SELECT [z-dds-step3-Unq-Facy-Part-Combinations].[Facility id],
[z-dds-step3-Unq-Facy-Part-Combinations].[Part Nbr], IIf([Vendor
Receipts]![Pieces]=Null,Null,[Vendor Receipts]![Pieces]) AS [1072 Pieces],
[Vendor Receipts].[Process id] AS 1072ID, IIf([Vendor
Receipts_1]![Pieces]=Null,Null,[Vendor Receipts_1]![Pieces]) AS [1079
Pieces], [Vendor Receipts_1].[Process id] AS 1079ID
FROM ([z-dds-step3-Unq-Facy-Part-Combinations] INNER JOIN [Vendor Receipts]
ON ([z-dds-step3-Unq-Facy-Part-Combinations].[Part Nbr] = [Vendor
Receipts].[Part Nbr]) AND ([z-dds-step3-Unq-Facy-Part-Combinations].[Facility
id] = [Vendor Receipts].[Facility id])) INNER JOIN [Vendor Receipts] AS
[Vendor Receipts_1] ON ([z-dds-step3-Unq-Facy-Part-Combinations].[Part Nbr] =
[Vendor Receipts_1].[Part Nbr]) AND
([z-dds-step3-Unq-Facy-Part-Combinations].[Facility id] = [Vendor
Receipts_1].[Facility id])
WHERE ((([Vendor Receipts].[Process id])="1072") AND (([Vendor
Receipts_1].[Process id])="1079"));
I tried to through in the checks for Null to maybe over-ride the in-correct
value from being displayed.
Sample Output:
Facility id Part Nbr 1072 Pieces 1072ID 1079 Pieces 1079ID
001 00003978 -200 1072 205 1079
001 00003978 -200 1072 210 1079
Desired Output:
Facility id Part Nbr 1072 Pieces 1072ID 1079 Pieces 1079ID
001 00003978 -200 1072 205 1079
001 00003978 210 1079
The Second -200 under 1072 Pieces is not present on the table. For that
condition there is only row for -200. Not 2 at the output appears to show
there is and this happens when ever there is an uneven amount of rows of data
for each detail grouping.
John Spencer said:
Based on your published sample data I don't see how you even got the current
output you are showing. Could you post the query you would use to get that
result?
Also, what logic tells you that qty 100 goes with qty 2500 and qty 125 goes
with qty 4300 and qty 278 has no match. Is it simply order of qty in
ascending size?
You could write a query to rank each qty by part and then use the ranking to
match up. That ASSUMES there would be no duplicate qty in either table.
SELECT B1.Part, B1.Qty, Count(B2.Part) as Rank
FROM B as B1 LEFT JOIN B as B2
On B1.Part = B2.Part
AND B1.Qty <= B2.Qty
GROUP BY B1.Part, B1.Qty
SELECT C1.Part, C1.Qty, Count(C2.Part) as Rank
FROM C as C1 LEFT JOIN C as C2
On C1.Part = C2.Part
AND C1.Qty <= C2.Qty
GROUP BY C1.Part, C1.Qty
Then using those two queries and assuming that B always has as many or more
records than C.
SELECT BQuery.Part, BQuery.Qty, CQuery.Qty
FROM BQuery LEFT JOIN CQuery
ON BQuery.Part = C.Query.Part
AND BQuery.Rank = C.QueryRank
Lots of assumptions and lots of chances for errors.
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
.