应收帐款汇总

本文介绍了一个复杂的SQL查询案例,该查询用于从多个表中选择特定时间段内的客户交易记录,并进行了一系列的数据转换和筛选操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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))


转载于:https://www.cnblogs.com/benio/archive/2010/12/31/1923535.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值