All Forums Analytics
ratu 8 posts Joined 10/09
06 Jan 2010
Calendar table calculation

Hi All,I am a newbi to this forum so can someone help me out.I am trying to get past 6 month/year numbers from a calendar table in TD. For example I can query the calendar table on the current month and it will give me this….Yr Mo2010 01Now how can I write a query so that Results set should look like this:Yr Mo 2009 122009 112009 102009 092009 082009 07It should be a rolling looking back 6 months, such as when current month is:Yr Mo2010 04Results set should look like this:Yr Mo 2010 032010 022010 012009 122009 112009 10Can anyone please help!Thanks!

Aj_yorkshire 1 post Joined 02/10
18 Feb 2010

Quick Example with the sys_calendar (Hope it helps):SELECT year_of_calendar, month_of_yearFROM sys_calendar.calendarWHERE calendar_date<=current_date AND EXTRACT(month FROM calendar_date)<> EXTRACT(MONTH FROM current_date) AND --because you want last 6 months and not current month calendar_date>current_date-INTERVAL '6' MONTHGROUP BY 1,2ORDER BY 1 DESC, 2 DESC;rgds,AJ

myokitis 6 posts Joined 03/10
29 Apr 2010

It helped me! Thanks AJ.

ganmku 9 posts Joined 04/10
06 May 2010

how come you are here...

Ganmku

You must sign in to leave a comment.