select CUSTOMER_NAME,
CUSTOMER_NUMBER,
extended_amount,
description,
price,
quantity,
saleName,
STARTDATE,
ENDDATE
from (
SELECT hpt.party_name CUSTOMER_NAME,
hca.account_number CUSTOMER_NUMBER,
decode(ctl.gross_extended_amount,
null,
ctl.extended_amount,
ctl.gross_extended_amount) as extended_amount,
ctl.description,
decode(ctl.gross_unit_selling_price,
null,
ctl.unit_selling_price,
ctl.gross_unit_selling_price) as price,
ARPT_SQL_FUNC_UTIL.get_salesrep_name_number(CT.PRIMARY_SALESREP_ID,
'NAME',
ct.org_id) as saleName,
NVL(CTL.QUANTITY_CREDITED, CTL.QUANTITY_INVOICED) as quantity,
TO_CHAR(:STARTDATE,'YYYY-MM-DD') AS STARTDATE,
TO_CHAR(:ENDDATE,'YYYY-MM-DD') AS ENDDATE
FROM ra_customer_trx_all ct,
ra_customer_trx_lines_all ctl,
hz_parties hpt,
hz_cust_accounts hca,
ra_cust_trx_types_all ctt,
mtl_units_of_measure uom
WHERE ct.customer_trx_id = ctl.customer_trx_id
AND ct.org_id = ctl.org_id
AND ct.bill_to_customer_id = hca.cust_account_id
AND hca.party_id = hpt.party_id
AND ctt.cust_trx_type_id = ct.cust_trx_type_id
AND ctl.line_type != 'TAX'
AND ctt.TYPE IN ('INV', 'CM')
AND ctt.cust_trx_type_id !=
cux_ar_utl_pkg.get_return_commitment_type
AND ctt.NAME != 'SH-内销开帐'
AND ctl.uom_code = uom.uom_code(+)
AND to_char(ct.trx_date, 'yyyy-mm-dd') BETWEEN TO_CHAR(:STARTDATE,'YYYY-MM-DD') AND TO_CHAR(:ENDDATE,'YYYY-MM-DD')
AND hca.account_number = nvl(:CUSTOMERNUM, hca.account_number)
)
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/24899662/viewspace-679417/
,如需转载,请注明出处,否则将追究法律责任。