?
Solved

Oracle data- Calendar display

Posted on 2013-12-12
2
Medium Priority
?
353 Views
Last Modified: 2013-12-17
I know flow01 had helped me earlier with this query

with s1
as
(select to_date('01-mar-2014','dd/mm/yyyy') startdate from dual)
,
t
as
(
select case to_char(startdate,'d')
       when '1' then startdate  -- if sunday than no shift needed
       else
        trunc(startdate,'day')
       end
       + (level - 1) h_date
        -- trunc 'day' returns the first day of the week : monday
        -- subtract 1 to get the sunday of that week
        -- add (level  - 1) to start from that sunday itself = level 1
      from s1
      connect by level <= 37  -- leafs 1 empty week when a regular february starts on sunday
)
SELECT to_char(t.h_date,'dd') day_of_month, to_char(t.h_date,'Dy') day_of_week , au, tp, both, tot, lcm,current_month_first_day
   from print_calendar a, t, s1
   where a.current_month_first_day(+) = t.h_date
   and t.h_date < add_months(startdate,1)  --  end with the last day of the month
order by t.h_date

My data has 3 months worth of data. Is there a possibility to get three months worth of data in this calendar?
data.txt
0
Comment
Question by:anumoses
2 Comments
 
LVL 78

Accepted Solution

by:
slightwv (䄆 Netminder) earned 1000 total points
ID: 39714556
I'm thinking it should just be two tweaks.

First one makes sure the connect by level returns more than enough rows to cover any 3 months.

The next, change add_months to the correct number of months.

with s1
as
(select to_date('01-mar-2014','dd/mm/yyyy') startdate from dual)
,
t
as
(
select case to_char(startdate,'d')
       when '1' then startdate
       else
        trunc(startdate,'day')
       end
       + (level - 1) h_date
      from s1
      connect by level <= 999
)
SELECT to_char(t.h_date,'dd') day_of_month, to_char(t.h_date,'Dy') day_of_week , au, tp, both, tot, lcm,current_month_first_day
   from tab_data a, t, s1
   where a.current_month_first_day(+) = t.h_date
   and t.h_date < add_months(startdate,3)
order by t.h_date
/

Open in new window

0
 
LVL 6

Author Closing Comment

by:anumoses
ID: 39724693
thanks
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
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.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
Suggested Courses

807 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