SELECT H.BUSINESS_UNIT
, H.INVOICE
, CNOTE.SEQ_NUM
, SNOTE.NOTE_TYPE
, SNOTE.TEXT254
, SNOTE.STD_NOTE_CD
FROM PS_CUST_NOTE CNOTE, PS_BI_HDR H
, PS_STD_NOTE SNOTE, PS_STD_NOTE_DOC SDOC
WHERE H.BILL_STATUS = 'INV'
AND H.BILL_TO_MEDIA = 'E'
AND CNOTE.CUST_ID = H.BILL_TO_CUST_ID
AND SNOTE.SETID = SDOC.SETID
AND SNOTE.STD_NOTE_CD = SDOC.STD_NOTE_CD
AND SNOTE.EFFDT = SDOC.EFFDT
AND SDOC.DOCUMENT_CD = 'INVC'
AND CNOTE.SETID = SNOTE.SETID
AND CNOTE.STD_NOTE_CD = SNOTE.STD_NOTE_CD
AND SNOTE.EFFDT = (SELECT MAX(EFFDT) FROM PS_STD_NOTE
WHERE SETID=SNOTE.SETID
AND STD_NOTE_CD = SNOTE.STD_NOTE_CD
AND EFFDT <= H.INVOICE_DT)
AND SNOTE.EFF_STATUS='A'
|