Hi,
I am trying to convert one column into multiple rows using UNPIVOT, and I am able to do it. But now, I am filtering the rows that needs to be converted into rows by joining another table. but its not working. Please find below query.
SELECT dmdunit,
dmdgroup,
loc,
fcstid,
MODEL,
dmdcal,
period,
nvl(lag(startdate+(vnum*7),1) over (PARTITION by dmdunit,loc order by dmdunit,loc,vnum),startdate)startdate,
nvl(lag(startdate+(vnum*7),1) over (PARTITION by dmdunit,loc order by dmdunit,loc,vnum),startdate)+6 enddate,
qty
FROM
(SELECT dmdunit,
dmdgroup,
loc,
startdate ,
startdate enddate,
type,
qty,
period,
fcstid,
model,
dmdcal,
ROW_NUMBER() OVER (PARTITION BY dmdunit,loc ORDER BY TO_NUMBER(SUBSTR(period,7)))vnum
FROM fcstwide fw,table2 t2
UNPIVOT INCLUDE NULLS
( qty FOR( period ) IN
(
PERIOD1 AS 'PERIOD1',
PERIOD2 AS 'PERIOD2',
PERIOD3 AS 'PERIOD3',
PERIOD4 AS 'PERIOD4',
PERIOD5 AS 'PERIOD5'
)
)
WHERE fw.dmdunit = t2.dmduinit
)ORDER BY dmdunit,loc
Does this work? I am getting error.
Edited by: BluShadow on 17-Oct-2011 15:45
added {noformat}
{noformat} tags. Please read {message:id=9360002} to learn to do this yourself.