Dear Members,
I have a sql as below:
select msi.segment1,
sum(CASE WHEN mdh.period_start_date > trunc(add_months(sysdate,-1))
THEN mdh.sales_order_demand ELSE 0 END) MONTH_USAGE_1
from mtl_demand_histories mdh,
mtl_system_items msi
where msi.inventory_item_id = mdh.inventory_item_id and
msi.organization_id = mdh.organization_id
group by segment1
From the above sql the 2nd column name(MONTH_USAGE_1) should be dynamic and the name can be derived from the following:
to_char(trunc(add_months(sysdate,-1)),'MON-RRRR') which will result in SEP-2010.
So the 2nd column name should be SEP-2010.
How can i do this in SQL.
Thanks
Sandeep