SELECT K.PROBINST , A.CAPTURE_ID , 1 FROM PS_RO_HEADER A , PS_RO_ASSOCIATION B , PS_RO_BAM_RUN_CTL D , PS_RO_BAM_RUN_INST K WHERE A.CAPTURE_ID = B.CAPTURE_ID AND A.CAPTURE_TYPE_CD = 'QUO' AND B.TYPE IN ('ROSO','ROS2') AND A.CAPTURE_DATE >= D.START_DATE AND A.CAPTURE_DATE <= D.END_DATE AND A.BULK_ORDER_FLAG <> 'Y' AND EXISTS ( SELECT 'X' FROM PS_RO_HEADER C , PS_RO_ASSOCIATION D , PS_RO_BAM_RUN_CTL X WHERE C.CAPTURE_ID = D.CAPTURE_ID_REL AND C.CAPTURE_TYPE_CD = 'SO' AND C.CAPTURE_DATE >= X.START_DATE AND C.CAPTURE_DATE <= X.END_DATE AND C.ROW_ADDED_DTTM >= A.ROW_ADDED_DTTM AND C.BUSINESS_UNIT = X.BUSINESS_UNIT ) AND D.OPRID=K.OPRID AND D.RUN_CNTL_ID=K.RUN_CNTL_ID
|