Subject | RE: [firebird-support] NOT EXISTS returns 'no current record for fetch operation' |
---|---|
Author | Leyne, Sean |
Post date | 2012-04-19T19:52:27Z |
Rick,
as to what I'm trying to accomplish, it's an outer
SELECT po.ID, pb.ID
FROM RPL_PO po
JOIN RPL_POBILL pb ON pb.PO = po.ID
WHERE
NOT EXISTS (
SELECT 1
FROM RPL_PO_ITM poi1
LEFT JOIN RPL_POBILL_ITM pbi1 ON poi1.NDC = pbi1.NDC AND pbi1.INVOICE = pb.ID
WHERE
Poi1.PURCH_ORDER = po.ID
AND pbi1.COST IS NULL
)
AND NOT EXISTS (
SELECT 1
FROM RPL_POBILL_ITM pbi2
LEFT JOIN RPL_PO_ITM poi2 ON poi2.NDC = pbi2.NDC AND poi2.PURCH_ORDER = po.ID
WHERE
Pbi2.INVOICE = pb.ID
AND poi2.PRICE IS NULL
)
And this?
SELECT po.ID, pb.ID
FROM RPL_PO po
JOIN RPL_POBILL pb ON (pb.PO = po.ID)
LEFT JOIN RPL_PO_ITM poi1 ON (poi1.PURCH_ORDER = po.ID)
LEFT JOIN RPL_POBILL_ITM pbi1 ON ((pbi1.NDC = poi1.NDC) AND (pbi1.INVOICE = pb.ID))
LEFT JOIN RPL_POBILL_ITM pbi2 ON (pbi2.INVOICE = pb.ID)
LEFT JOIN RPL_PO_ITM poi2 ON ((poi2.NDC = pbi2.NDC) AND (poi2.PURCH_ORDER = po.ID))
WHERE
AND pbi1.COST IS NULL
AND poi1.NDC IS NULL
AND poi2.NDC IS NULL
AND poi2.PRICE IS NULL
Sean
> In case anyone is confusedCount me as one of them!
as to what I'm trying to accomplish, it's an outer
> join on line items where both sides match with no NULL items.What happens with this query?
> If my approach is poor, then I won't have to worry about question about the
> exception.
>
SELECT po.ID, pb.ID
FROM RPL_PO po
JOIN RPL_POBILL pb ON pb.PO = po.ID
WHERE
NOT EXISTS (
SELECT 1
FROM RPL_PO_ITM poi1
LEFT JOIN RPL_POBILL_ITM pbi1 ON poi1.NDC = pbi1.NDC AND pbi1.INVOICE = pb.ID
WHERE
Poi1.PURCH_ORDER = po.ID
AND pbi1.COST IS NULL
)
AND NOT EXISTS (
SELECT 1
FROM RPL_POBILL_ITM pbi2
LEFT JOIN RPL_PO_ITM poi2 ON poi2.NDC = pbi2.NDC AND poi2.PURCH_ORDER = po.ID
WHERE
Pbi2.INVOICE = pb.ID
AND poi2.PRICE IS NULL
)
And this?
SELECT po.ID, pb.ID
FROM RPL_PO po
JOIN RPL_POBILL pb ON (pb.PO = po.ID)
LEFT JOIN RPL_PO_ITM poi1 ON (poi1.PURCH_ORDER = po.ID)
LEFT JOIN RPL_POBILL_ITM pbi1 ON ((pbi1.NDC = poi1.NDC) AND (pbi1.INVOICE = pb.ID))
LEFT JOIN RPL_POBILL_ITM pbi2 ON (pbi2.INVOICE = pb.ID)
LEFT JOIN RPL_PO_ITM poi2 ON ((poi2.NDC = pbi2.NDC) AND (poi2.PURCH_ORDER = po.ID))
WHERE
AND pbi1.COST IS NULL
AND poi1.NDC IS NULL
AND poi2.NDC IS NULL
AND poi2.PRICE IS NULL
Sean