You are on page 1of 2

select *

from (select cm_transaction_id,


cm_amount,
bdres_amount,
nvl (link_amt, 0) link_amt,
nvl (jrnl_151_amount, 0) jrnl_151_amount,
nvl (cm_amount_foreign, 0) cm_amount_foreign,
nvl (bdres_amount_foreign, 0) bdres_amount_foreign,
nvl (link_amt_foreign, 0) link_amt_foreign,
nvl (jrnl_151_amount_foreign, 0) jrnl_151_amount_foreign
from zzres_w_jrnl_prdb) omsdata,
(select cm_transaction_id, cm_amount_foreign_linked_zline
from stg_writeoff) prdbdata
where omsdata.cm_transaction_id = prdbdata.cm_transaction_id

with omsdata as(


SELECT
cm_transaction_id,
cm_amount,
bdres_amount,
nvl(link_amt, 0) link_amt,
nvl(jrnl_151_amount, 0) jrnl_151_amount,
nvl(cm_amount_foreign, 0) cm_amount_foreign,
nvl(bdres_amount_foreign, 0) bdres_amount_foreign,
nvl(link_amt_foreign, 0) link_amt_foreign,
nvl(jrnl_151_amount_foreign, 0) jrnl_151_amount_foreign
FROM
zzres_w_jrnl_prdb
) ,
prdbdata as (
SELECT
*
FROM
stg_writeoff
where WRITE_OFF_NAME = 'BAD DEBT'
)
select sum(CM_AMOUNT_FOREIGN_WRLINE) from prdbdata where not exists (
select 1 from omsdata where omsdata.cm_transaction_id =prdbdata.cm_transaction_id
) ; -- in staging not in oms Bad debt reserve

select sum(cm_amount),sum(link_amt) , sum(cm_amount) + sum(link_amt) from omsdata

select sum(CM_AMOUNT_FOREIGN_WRLINE) from prdbdata where not exists (


select 1 from omsdata where omsdata.cm_transaction_id =prdbdata.cm_transaction_id
) ;

with omsdata as(


SELECT
cm_transaction_id,
cm_amount,
bdres_amount,
nvl(link_amt, 0) link_amt,
nvl(jrnl_151_amount, 0) jrnl_151_amount,
nvl(cm_amount_foreign, 0) cm_amount_foreign,
nvl(bdres_amount_foreign, 0) bdres_amount_foreign,
nvl(link_amt_foreign, 0) link_amt_foreign,
nvl(jrnl_151_amount_foreign, 0) jrnl_151_amount_foreign
FROM
zzres_w_jrnl_prdb
) ,
prdbdata as (
SELECT
*
FROM
stg_writeoff
where WRITE_OFF_NAME = 'BAD DEBT'
)
select sum(cm_amount),sum(link_amt) , sum(cm_amount) - sum(link_amt) from
omsdata,prdbdata where prdbdata.cm_transaction_id =prdbdata.cm_transaction_id

select sum(CM_AMOUNT_FOREIGN_WRLINE) from prdbdata where not exists (


select 1 from omsdata where omsdata.cm_transaction_id =prdbdata.cm_transaction_id
) ;

You might also like