?
Solved

Dates between date ranges - oracle 10

Posted on 2010-11-20
3
Medium Priority
?
678 Views
Last Modified: 2013-12-18
Please see the attached displaying:
fig 1. current output from o_assessments table
fig 2. desired output

the requirements:
the output needs to list all days which the assessments cover, (i.e. the days between the start and end date).

I’m only interested in assessments which cover a set time period (so in this instance just Jan-09), although I’d like to be able to change the to and from dates to cover a wider range of dates if necessary)

If no assessments took place on a certain date I’d still like that date to be listed. (Eg 21-Jan- 24-Jan in this instance)

An assessment needs to be given an order number (asm_ordering) this is ordered by the start date of the assessment (in this instance REF would be 1 as started in December, then CORE (01/01/2009) as 2, IA (03/01/2009) as 3 etc

Any help is appreciated.

example-table-2.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
3 Comments
 
LVL 32

Expert Comment

by:awking00
ID: 34179961
See attached. Note - your example shows 1/16/2009,CORE,A198035,2 twice, which I think is a copy and paste error.

select asm_date
      ,asm_type
      ,asm_id
      ,decode(asm_type,'REF',1
                     ,'CORE',2
                     ,'IA',3
                     ,'SECT47',4) asm_ordering
from
((select trunc(to_date('20081231','yyyymmdd')) + level as asm_date
  from dual
  connect by level <= 31) x
 left join
 o_assessments a
 on x.asm_date >= a.asm_start_date
 and x.asm_date <= a.asm_end_date)
order by x.asm_date,decode(asm_type,'REF',1,'CORE',2,'IA',3,'SECT47',4)
;

Open in new window

0
 
LVL 74

Accepted Solution

by:
sdstuber earned 2000 total points
ID: 34180058
try this...

simply change the january 1 date to whatever month you want, it will determine the correct number of days on its own.
The ordering is based on the asm_start_date and will be dynamic as other rows are added.


SELECT asm_date,
       asm_type,
       asm_id,
       CASE
           WHEN asm_type IS NOT NULL
           THEN
               DENSE_RANK() OVER (ORDER BY asm_start_date)
       END
           asm_ordering
  FROM     o_assessments
       RIGHT OUTER JOIN
           (SELECT TO_DATE('2009-01-01', 'yyyy-mm-dd') + LEVEL - 1 asm_date
              FROM DUAL
            CONNECT BY TO_DATE('2009-01-01', 'yyyy-mm-dd') + LEVEL - 1 <=
                           LAST_DAY(TO_DATE('2009-01-01', 'yyyy-mm-dd')))
       ON asm_date BETWEEN asm_start_date AND asm_end_date
ORDER BY asm_date, asm_ordering
0
 
LVL 3

Expert Comment

by:mpaladugu
ID: 34180255
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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 explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Suggested Courses

752 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