Depending on the database version, you could use an ugly query like this:
<pre>WITH temp AS (SELECT entered,ADD_MONTHS(entered,DECODE(MOD(TO_CHAR(entered,'mm'),3),0,0,3-MOD(TO_CHAR(entered,'mm'),3))) next
FROM (SELECT TO_DATE('01'||'&per','ddmonyyyy') entered FROM dual) t)
SELECT TO_CHAR(ADD_MONTHS(next,-12),'monyyyy') period,1 FROM temp
UNION SELECT TO_CHAR(add_months(next,-9),'monyyyy'),2 FROM temp
UNION SELECT TO_CHAR(add_months(next,-6),'monyyyy'),3 FROM temp
UNION SELECT TO_CHAR(add_months(next,-3),'monyyyy'),4 FROM temp
UNION SELECT TO_CHAR(entered,'monyyyy'),5 FROM temp
ORDER BY 2;</pre>
Maybe some kind of recursive query could be used as well.
And, I guess there are more elegant (and probably easier) ways to do it.
Are the periods stored in a table ? If so, what is its structure ?
What have you tried ?
hello,
thanks for reply ..
No , the period must be passed at run time .. and acoording to passed parameter , it should return the value.