Access 2002 will not accept this query - Ambiguous Outer Join. But I
can't see how to get the recordset I need without an Ambiguous Outer
Join ? Here is the query as it currently stands:
SELECT "OEINVD"."I TEM" as "Item #", "OEINVD"."QTYSH IPPED" as "Quantity
Shipped", "OEINVD"."EXTIN VMISC" as "$ Sales", "OEINVD"."EXTIC OST" as
"$COGS", "OEINVH"."INVNU MBER" as "Invoice #", "OEINVH"."CUSTO MER" as
"Customer", "OECRDH"."CRDNU MBER" as "Credit Note #",
SUM("OECRDD"."Q TYRETURN") as "Quantity
Returned",SUM(" OECRDD"."EXTCRD MISC") as "$ Return",
SUM("OECRDD"."E XTCCOST") as "$ Return COGS"
FROM (("OEINVD" INNER JOIN "OEINVH" ON "OEINVD"."INVNU MBER" =
"OEINVH"."INVNU MBER") LEFT OUTER JOIN "OECRDH" ON "OEINVH"."INVNU MBER"
= "OECRDH"."INVNU MBER") INNER JOIN "OECRDD" ON "OECRDH"."CRDUN IQ" =
"OECRDD"."CRDUN IQ"
WHERE "OEINVD"."QTYSH IPPED">0 AND "OEINVH"."INVDA TE">20040501 AND
"OEINVD.ITE M" = "OECRDD.ITE M"
GROUP BY "OEINVD"."ITEM" , "OEINVD"."QTYSH IPPED",
"OEINVD"."EXTIN VMISC",
"OEINVD"."EXTIC OST","OEINVH"." INVNUMBER","OEI NVH"."CUSTOMER" ,
"OEINVH"."INVDA TE", "OECRDH"."CRDNU MBER";
......
OEINVH & OEINVD represent invoices, and are linked to each other via
inner join on INVNUMBER
OECRDH and OECRDD represent credit notes and are linked to each other
via inner join on CRDUNIQ
What I'm trying to do is list all the invoice detail lines (OEINVD)
with credit note information if applicable. My first problem is that
the detail level information for credit notes is in OECRDD. The only
way I can see to link from OEINVD is:
OEINVD.INVNUMER = OEINVH.INVNUMBE R
OEINVH.INVNUMBE R OuterLeft OECRDH.INVNUMBE R
OECRDH.CRDUNIQ = OECRDD.CRDUNIQ
OEINVD.ITEM = OECRDD.ITEM
I need that last join, otherwise the recordset would have incorrect
summing on the credit note side.
My second issue is this - not every invoice has a credit note, and
just to make life difficult, there can be > 1 credit note against an
invoice! So in other words an invoice could have 0,1 or more credit
notes against it. Where there is > 1 credit note against an invoice I
want to sum the credit note fields.
I've come to a dead end, how can I get this working ?
Thanks
Bill
can't see how to get the recordset I need without an Ambiguous Outer
Join ? Here is the query as it currently stands:
SELECT "OEINVD"."I TEM" as "Item #", "OEINVD"."QTYSH IPPED" as "Quantity
Shipped", "OEINVD"."EXTIN VMISC" as "$ Sales", "OEINVD"."EXTIC OST" as
"$COGS", "OEINVH"."INVNU MBER" as "Invoice #", "OEINVH"."CUSTO MER" as
"Customer", "OECRDH"."CRDNU MBER" as "Credit Note #",
SUM("OECRDD"."Q TYRETURN") as "Quantity
Returned",SUM(" OECRDD"."EXTCRD MISC") as "$ Return",
SUM("OECRDD"."E XTCCOST") as "$ Return COGS"
FROM (("OEINVD" INNER JOIN "OEINVH" ON "OEINVD"."INVNU MBER" =
"OEINVH"."INVNU MBER") LEFT OUTER JOIN "OECRDH" ON "OEINVH"."INVNU MBER"
= "OECRDH"."INVNU MBER") INNER JOIN "OECRDD" ON "OECRDH"."CRDUN IQ" =
"OECRDD"."CRDUN IQ"
WHERE "OEINVD"."QTYSH IPPED">0 AND "OEINVH"."INVDA TE">20040501 AND
"OEINVD.ITE M" = "OECRDD.ITE M"
GROUP BY "OEINVD"."ITEM" , "OEINVD"."QTYSH IPPED",
"OEINVD"."EXTIN VMISC",
"OEINVD"."EXTIC OST","OEINVH"." INVNUMBER","OEI NVH"."CUSTOMER" ,
"OEINVH"."INVDA TE", "OECRDH"."CRDNU MBER";
......
OEINVH & OEINVD represent invoices, and are linked to each other via
inner join on INVNUMBER
OECRDH and OECRDD represent credit notes and are linked to each other
via inner join on CRDUNIQ
What I'm trying to do is list all the invoice detail lines (OEINVD)
with credit note information if applicable. My first problem is that
the detail level information for credit notes is in OECRDD. The only
way I can see to link from OEINVD is:
OEINVD.INVNUMER = OEINVH.INVNUMBE R
OEINVH.INVNUMBE R OuterLeft OECRDH.INVNUMBE R
OECRDH.CRDUNIQ = OECRDD.CRDUNIQ
OEINVD.ITEM = OECRDD.ITEM
I need that last join, otherwise the recordset would have incorrect
summing on the credit note side.
My second issue is this - not every invoice has a credit note, and
just to make life difficult, there can be > 1 credit note against an
invoice! So in other words an invoice could have 0,1 or more credit
notes against it. Where there is > 1 credit note against an invoice I
want to sum the credit note fields.
I've come to a dead end, how can I get this working ?
Thanks
Bill
Comment