Sunday, 8 July 2018

Oracle Credit-Debit Invoice Reference Invoice No Query

SELECT
SUBSTR (SYS_CONNECT_BY_PATH (trx_number , ','), 2) CM_DM_REF_INV_NO
--- INTO v_OU_VAT_REG_NO
      FROM (SELECT rcta2.trx_number,ROW_NUMBER () OVER (ORDER BY rcta2.trx_number ) rn, COUNT (*) OVER () cnt
    FROM RA_CUSTOMER_TRX_ALL rcta1,
         RA_CUSTOMER_TRX_ALL rcta2,
         AR_RECEIVABLE_APPLICATIONS_ALL araa
   WHERE --rcta1.trx_number = CM_DM_IINV_NO
   rcta1.customer_trx_id=CM_DM_CUST_TRX_ID
     AND araa.status = 'APP' --applied
     AND araa.display = 'Y'  --Not UNapplied
     AND rcta1.customer_trx_id = araa.customer_trx_id
     AND rcta2.customer_trx_id = araa.APPLIED_CUSTOMER_TRX_ID
ORDER BY apply_date ASC
)
     WHERE rn = cnt
START WITH rn = 1
CONNECT BY rn = PRIOR rn + 1;

No comments:

Post a Comment