|
cherman
Starting Member
15 Posts |
Posted - 2011-05-04 : 16:30:59
|
| select 1 sort, b.bkr_cd, b.bkr_name, o.prin_local_crrncy, c.crrncy_name, o.net_trade_ind, o.broker_reason, (select cod.desc_text from csm_code cod where cod.desc_type='BKRRNE' and cod.desc_cd=o.broker_reason)broker_reason_desc, sum(oa.commision_amt)comm_amt, case when o.broker_reason is null then (select sum(oa1.commision_amt) from ts_order o1, ts_order_alloc oa1 where oa1.order_id=o1.order_id and o1.settle_date>=dateadd(year, datediff(year, '1900-01-01', getdate()), '1900-01-01') --and o1.settle_date'Y' or o1.ipo is null) else (select sum(oa1.commision_amt) from ts_order o1, ts_order_alloc oa1 where oa1.order_id=o1.order_id and o1.settle_date>=dateadd(year, datediff(year, '1900-01-01', getdate()), '1900-01-01') --and o1.settle_date'Y' or o1.ipo is null)end bkr_prin_ytd, 0 bkr_rea_prin_ytd, 0 bkr_rea_agcy_ytd, b.bkr_typ_cd, b.credit_ratio, b.credit_bkr_cd, oa.bkr_of_credit, oa.exec_broker, --bk.target_amt, oa.step_out_broker, '' exec_or_credit, 'ob' row_type from ts_order o, ts_order_alloc oa, cs_broker b, --cs_fund_broker bk, csm_currency c where oa.order_id=o.order_id --and o.exec_broker=bk.acct_cd and((oa.exec_broker=b.bkr_cd and(oa.step_out_broker is null or oa.step_out_broker='')) or(oa.step_out_broker=b.bkr_cd)) and(oa.bkr_of_credit is null) and o.prin_local_crrncy=c.crrncy_cd and(o.reason_cd not in('IPO', 'PP', 'SO') or o.reason_cd is null) and(o.ipo<>'Y' or o.ipo is null) and((o.status in('ACCT') or(o.status in('ACCT') and 'Y'='N')) and o.trade_date>='2011-01-01' and o.trade_date<='2011-01-31' and b.bkr_cd in(select blm.bkr_cd from cs_broker_list_member blm where blm.bkr_list_cd='EQUITY') and 1=1) (select bk.target_amt from cs_fund_broker bk where oa.exec_broker = bk.acct_cd)as target_amtgroup by b.bkr_cd, b.bkr_name, o.prin_local_crrncy, c.crrncy_name, o.broker_reason, o.net_trade_ind, b.bkr_typ_cd, b.credit_ratio, b.credit_bkr_cd, oa.bkr_of_credit, oa.exec_broker, oa.step_out_broker --bk.target_amt union all select 2 sort, b.bkr_cd, b.bkr_name, o.prin_local_crrncy, c.crrncy_name, o.net_trade_ind, o.broker_reason, (select cod.desc_text from csm_code cod where cod.desc_type='BKRRNE' and cod.desc_cd=o.broker_reason)broker_reason_desc, sum(oa.commision_amt)comm_amt, case when o.broker_reason is null then (select sum(oa1.commision_amt) from ts_order o1, ts_order_alloc oa1 where oa1.order_id=o1.order_id and o1.settle_date>=dateadd(year, datediff(year, '1900-01-01', getdate()), '1900-01-01') --and o1.settle_date'Y' or o1.ipo is null) else (select sum(oa1.commision_amt) from ts_order o1, ts_order_alloc oa1 where oa1.order_id=o1.order_id and o1.settle_date>=dateadd(year, datediff(year, '1900-01-01', getdate()), '1900-01-01') --and o1.settle_date'Y' or o1.ipo is null)end bkr_prin_ytd, 0 bkr_rea_prin_ytd, 0 bkr_rea_agcy_ytd, b.bkr_typ_cd, b.credit_ratio, b.credit_bkr_cd, oa.bkr_of_credit, oa.exec_broker, --bk.target_amt, oa.step_out_broker, 'FromExec' exec_or_credit, 'oa' row_typefrom ts_order o, ts_order_alloc oa, cs_broker b, --cs_fund_broker bk, csm_currency c where oa.order_id=o.order_id --and o.exec_broker=bk.acct_cd and((oa.exec_broker=b.bkr_cd and(oa.step_out_broker is null or oa.step_out_broker='')) or(oa.step_out_broker=b.bkr_cd)) and(oa.bkr_of_credit is not null) and o.prin_local_crrncy=c.crrncy_cd and(o.reason_cd not in('IPO', 'PP', 'SO') or o.reason_cd is null) and(o.ipo<>'Y' or o.ipo is null) and((o.status in('ACCT') --or(o.status in('ACCT', 'READY') and 'Y'='N') and o.trade_date>='2011-01-01' and o.trade_date<='2011-01-31' and b.bkr_cd in(select blm.bkr_cd from cs_broker_list_member blm where blm.bkr_list_cd='EQUITY') and 1=1)group by b.bkr_cd, b.bkr_name, o.prin_local_crrncy, c.crrncy_name, o.broker_reason, o.net_trade_ind, b.bkr_typ_cd, b.credit_ratio, b.credit_bkr_cd, oa.bkr_of_credit, oa.exec_broker, oa.step_out_broker --bk.target_amt |
 |
|