Moving Date Window
872304Jun 29 2011 — edited Jul 7 2011Hello All,
I have a Table X with a Date column "TestDate". I need to query for every year (start date is dynamically picked up for each row and end date is always the Sysdate) where value of MyCode='10' (say).
For every year from the start date to end date i need to query for some data existing in all the date windows (examples below).
SQL:
desc X;
TestDate date;
MyCode varchar2(55);
Example 1 ;
StartDate = Jun 2008 (Dynamic date each row)
Sysdate = Jun 2011 (Current date)
If for one row i have a start date as June 2008 and sysdate is Jun 29 2011 (todays)
then for every year from the start date + 4 months to start date + 9 months i need to check for some data .
Condition is that it should exist in every year from StartDate to Sysdate (meaning a row should exist in this case in 2008 and 2009 and 2010 and 2011)
Should exist in --
StartDate +4 months to Start Date + 9 months (for 2008)
StartDate +4 months to Start Date + 9 months (for 2009)
StartDate +4 months to Start Date + 9 months (for 2010)
StartDate +4 months to Start Date + 9 months (for 2011)
Example 2;
Start date = Feb 2007 (Dynamic value)
Sysdate = Jun 29 2011 (Todays date)
Check for a row in Date window for every year from --
StartDate +4 months to Start Date + 9 months (for 2007)
StartDate +4 months to Start Date + 9 months (for 2008)
StartDate +4 months to Start Date + 9 months (for 2009)
StartDate +4 months to Start Date + 9 months (for 2010)
StartDate +4 months to Start Date + 9 months (for 2011)
Can someone please help me out in querying such data ? Thank you.
Edited by: 869301 on Jun 29, 2011 2:51 PM