Solved

List of date in previous 4 months - oracle 10 sql

Posted on 2010-11-29
3
619 Views
Last Modified: 2012-05-10
I need a query to list all dates in the last 6 months.
for example eg. we're currently in November,  so if i ran the query today it would list dates back to May. The first date always needs to be a friday so in this instance it will return the 1st Friday before the 1st of May (or return the 1st of may if its a friday), the last day would be the last friday before today (or today if today was friday). I hope this makes sense - i'll include some sample data which will hopefully make my requirments clearer.
sample-dates.xls
0
Comment
Question by:tonMachine100
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 74

Expert Comment

by:sdstuber
ID: 34232446
try this...

select next_day(add_months(trunc(sysdate,'mm'),-6)-7,'Friday') + level - 1 d from dual
connect by next_day(add_months(trunc(sysdate,'mm'),-6)-7,'Friday') + level <= sysdate
0
 
LVL 74

Accepted Solution

by:
sdstuber earned 500 total points
ID: 34232473
oops, forgot the end point condition

change

+ level <= sysdate

to

+ level-1 <= next_day(sysdate-7,'Friday')
0
 

Author Closing Comment

by:tonMachine100
ID: 34237787
Thanks- thats spot on
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question