SELECT
wal.code_combination_id ccid
,cc.concatenated_segments
,bg.short_name bgname
,sp.service_package_short_name spname
,wal.currency_code
,sum(decode(budget_year_id,:p_budgeT_group_id1 ,nvl(ytd_amount,0),0)) y1_amt
,sum(decode(budget_year_id,:p_budget_group_id2 ,nvl(ytd_amount,0),0)) y2_amt
,sum(decode(budget_year_id,:p_budget_group_id3 ,nvl(ytd_amount,0),0)) y3_amt
,sum(decode(budget_year_id,:p_budget_group_id4 ,nvl(ytd_amount,0),0)) y4_amt
FROM psb_ws_account_lines wal
,psb_ws_lines wl
,psb_worksheets ws
,psb_ws_service_packages_v sp
,psb_budget_groups bg
, gl_code_combinations_kfv cc
where ws.worksheet_id = :p_global_worksheet_id and
cc.code_combination_id = wal.code_combination_id and
((:cp_sequence_number is NULL and wal.end_stage_seq is null ) OR
ws.current_stage_seq = :cp_sequence_number )
and
( (:p_service_package_id is not null and sp.service_package_id = :p_service_package_id) or
(:p_service_package_id is null ) ) and
wl.worksheet_id = ws.worksheet_id and
wl.worksheet_id = sp.worksheet_id and
sp.service_package_id = wal.service_package_id and
wal.balance_type = 'E' and
wl.account_line_id = wal.account_line_id and
bg.budget_group_id = wal.budget_group_id and
cc.summary_flag = 'N'
group by bg.short_name,sp.service_package_short_name ,wal.code_combination_id,cc.concatenated_segments, currency_code
order by bg.short_name |