SELECT A.BUSINESS_UNIT , B.WORK_ORDER_ID , B.PO_ID , B.PO_LINE_NBR , A.INVOICE_ID , A.INVOICE_LINE , A.VENDOR_ID , A.VNDR_LOC FROM PS_SPF_INVOICE_RPT A , PS_SPF_WO_PO_DTL B WHERE A. BUSINESS_UNIT = B.BUSINESS_UNIT AND A.WORK_ORDER_ID = B.WORK_ORDER_ID AND B.SEQNUM = 1 AND (A.TIME_SHEET_ID <> ' ' OR A.PLOG_ID <> ' ') UNION SELECT A.BUSINESS_UNIT , B.WORK_ORDER_ID , B.PO_ID , B.PO_LINE_NBR , A.INVOICE_ID , A.INVOICE_LINE , A.VENDOR_ID , A.VNDR_LOC FROM PS_SPF_INVOICE_RPT A , PS_SPF_WO_PO_DTL B WHERE A. BUSINESS_UNIT = B.BUSINESS_UNIT AND A.WORK_ORDER_ID = B.WORK_ORDER_ID AND B.SEQNUM = 2 AND A.SHEET_ID <> ' ' UNION SELECT A.BUSINESS_UNIT , B.WORK_ORDER_ID , B.PO_ID , 0 , A.INVOICE_ID , A.INVOICE_LINE , A.VENDOR_ID , A.VNDR_LOC FROM PS_SPF_INVOICE_RPT A , PS_SPF_WORDERREC B WHERE A. BUSINESS_UNIT = B.BUSINESS_UNIT AND A.WORK_ORDER_ID = B.WORK_ORDER_ID AND A.WORK_ORDER_ID NOT IN ( SELECT DISTINCT WORK_ORDER_ID FROM PS_SPF_WO_PO_DTL WHERE PS_SPF_WO_PO_DTL.BUSINESS_UNIT = A.BUSINESS_UNIT)
|