This query returns 'no current record for fetch operation' SELECT po.ID, pb.ID FROM RPL_PO po JOIN RPL_POBILL pb ON pb.PO = po.ID WHERE po.ID = ? AND NOT EXISTS ( SELECT 1 FROM RPL_PO_ITM poi LEFT JOIN RPL_POBILL_ITM pbi ON poi.NDC = pbi.NDC AND pbi.INVOICE = pb.ID WHERE poi.PURCH_ORDER = po.ID AND pbi.COST IS NULL )
But these running the queries separately works. SELECT po.ID, pb.ID FROM RPL_PO po JOIN RPL_POBILL pb ON pb.PO = po.ID WHERE po.ID = ? /* plug in values returned above */ SELECT * FROM RPL_PO_ITM poi LEFT JOIN RPL_POBILL_ITM pbi ON poi.NDC = pbi.NDC AND pbi.INVOICE = pb.ID WHERE poi.PURCH_ORDER = po.ID AND pbi.COST IS NULL Disclaimer: This message (including attachments) is confidential and may be privileged. If you have received it by mistake please notify the sender by return e-mail and delete this message from your system. Any unauthorized use or dissemination of this message in whole or in part is strictly prohibited. Please note that e-mails are susceptible to change. RxStrategies, Inc. shall not be liable for the improper or incomplete transmission of the information contained in this communication or for any delay in its receipt or damage to your system. RxStrategies, Inc. does not guarantee that the integrity of this communication has been maintained nor that this communication is free from viruses, interceptions or interference.