Our auditors want to know which items had their costs updated in March 2006. I'm querying the cst_standard_cost table to find records that were updated in March. This part seems to be working although it pulls back multiple rows for the same item if more than one update was done in that month. I'm still not sure how I'm going to handle that problem.
----cst_standard_costs-----
alter session set NLS_DATE_FORMAT = 'MM/DD/YYYY';
drop table suss.cost_update_0306b;
create table suss.cost_update_0306b
as
select csc.inventory_item_id, mtl.segment1||','||mtl.segment2 "item", csc.organization_id,csc.standard_cost,csc.creation_date "creation_date"
from cst_standard_costs csc, mtl_system_items_b mtl
where csc.inventory_item_id = mtl.inventory_item_id
and mtl.organization_id = '82'
and csc.organization_id not in ('0','81')
and csc.creation_date like '03/%/2006%'
order by csc.inventory_item_id
Here, I'm trying to find if the update that was done in March actually changed the item's cost. But the sql is not exactly right. The results being returned are any cost update where the item's cost is different than it was in March. I'd like to pull back the item's cost from the most recent cost update previous to the March update and see if it differs from the March cost.
select csc.inventory_item_id,mtl.segment1||','||mtl.segment2, csc.organization_id,csc.standard_cost, csc.creation_date
from cst_standard_costs csc, mtl_system_items_b mtl, suss.cost_update_0306b scu
where csc.inventory_item_id = mtl.inventory_item_id
and mtl.organization_id = '82'
and scu.inventory_item_id = csc.inventory_item_id
and csc.organization_id not in ('0','81')
and csc.creation_date < scu."creation_date"
and csc.standard_cost <>scu.standard_cost
order by csc.inventory_item_id asc
Here's a simple example
item id.....cost.........update_date
24..........45.00........03/01/2006
24..........45.00........02/01/2006
24..........30.00........02/22/2006
40..........45.00........03/01/2006
40..........30.00........02/01/2006
40..........28.00........02/22/2006
The results of the sql should be to return item id 40 because the costs changed in March but not item id 24 because the costs did not change in March