SELECT a.common_id ,a.business_unit ,a.item_term ,a.last_activity_date ,d.descr ,a.currency_cd ,SUM(a.item_amt) FROM ps_item_sf a , ps_bus_unit_tbl_sf c , PS_ITEM_TYPE_TBL d WHERE a.sa_id_type = 'P' AND a.business_unit = c.business_unit AND a.item_type = d.item_type AND d.item_type_cd IN ('A','C','H','X','B','W') AND d.setid = ( SELECT e.setid FROM ps_set_cntrl_rec e WHERE e.setcntrlvalue = c.institution AND e.recname = 'ITEM_TYPE_TBL') AND d.effdt = ( SELECT MAX(f.effdt) FROM PS_ITEM_TYPE_TBL f WHERE f.setid = d.setid AND f.item_type = d.item_type AND f.effdt <= %CurrentDateIn) AND d.eff_status = 'A' GROUP BY a.common_id, a.common_id, a.business_unit, a.item_term, a.last_activity_date, d.descr, a.currency_cd
|