SELECT
pos.name posid
,bg.short_name bgname
,sp.service_package_short_name spname
,elm.currency_code currency_code
,round(sum(decode(budget_year_id,:p_budgeT_group_id1 ,nvl(element_cost,0),0)), 2) y1_amt
,round(sum(decode(budget_year_id,:p_budget_group_id2 ,nvl(element_cost,0),0)), 2) y2_amt
,round(sum(decode(budget_year_id,:p_budget_group_id3 ,nvl(element_cost,0),0)), 2) y3_amt
,round(sum(decode(budget_year_id,:p_budget_group_id4 ,nvl(element_cost,0),0)), 2) y4_amt
FROM psb_ws_element_lines elm
,psb_ws_lines_positions lp
,psb_ws_position_lines pl
,psb_ws_service_packages_v sp
,psb_budget_groups bg
,psb_positions pos
where lp.worksheet_id = :p_global_worksheet_id and
((:cp_sequence_number is NULL AND elm.end_stage_seq is NULL) or
elm.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
sp.service_package_id = elm.service_package_id and
lp.worksheet_id = sp.worksheet_id and
elm.position_line_id = lp.position_line_id and
pl.position_line_id = lp.position_line_id and
bg.budget_group_id = pl.budget_group_id and
pos.position_id = pl.position_id and
pl.copy_of_position_line_id is null and
elm.end_stage_seq is null
group by bg.short_name,sp.service_package_short_name,pos.name,elm.currency_code
ORDER BY 2 ASC |