?
Solved

oracle date query

Posted on 2012-04-04
15
Medium Priority
?
327 Views
Last Modified: 2012-04-05
Need a parameter for No of weeks of schedule.

define d_first_day_week  date
= date(7- mod(days(sysdate) , 7)) + (days(sysdate)) - 7)

define d_weeks  date =
date(days(d_first_day_week) + nconvert(getsys(parameter_name)) * 7)

Need help inh translating this to oracle
so that I can use in the query

select  a.department_id,a.payroll_id,
        a.schedule_date,a.start_time,a.start_ampm,
        a.end_time,a.end_ampm,a.total_hours,
        a.short_description,s.site_name,s.city_name
from off_duty a, sites s,blood_drives bd
where a.site_code = s.site_code(+)
and a.site_code = bd.site_code(+)
and a.schedule_date = bd.drive_date(+)      
and a.department_id = 5
and a.schedule_date = parameter_name(no of weeks of schedule)
0
Comment
Question by:anumoses
[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
  • 8
  • 5
  • 2
15 Comments
 
LVL 74

Expert Comment

by:sdstuber
ID: 37807604
you have declarations that use non-Oracle functions  - what do those functions do?

you have a query that uses another non-Oracle function - what does that function do?


there is no input, nor expected output
what is the question?
0
 
LVL 6

Author Comment

by:anumoses
ID: 37808301
The logic is I have to use 1 to 5 weeks.
The first day has to be a sunday. so 1 - sunday to saturday. (april 8th to april 14th  2012)
2 weeks -( april 8th to april 21st 2012).
So when the user puts 1 then I have to to take the schedule_date = to that parameter. Internally convert 1 to sunday to saturday
0
 
LVL 6

Author Comment

by:anumoses
ID: 37808309
No I take back. I will post very soon what is required
0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
LVL 74

Expert Comment

by:sdstuber
ID: 37808324
>>> convert 1 to sunday

I understand that part,    

DECODE(n,
              1, 'Sunday',
              2, 'Monday',
              3, 'Tuesday',
              4, 'Wednesday',
              5, 'Thursday',
              6, 'Friday',
              7, 'Saturday'
             )



the rest I still don't know what you want to do.  Please provide sample data and expected output.
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 37808326
sorry, didn't see the second post
0
 
LVL 6

Author Comment

by:anumoses
ID: 37808337
OK. here it is. If I am running the report today, then today is 4th april 2012. So I have to go back to sunday ie is the 1st april. Then from that sunday add no of weeks schedule, (1-5)
0
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 37808344
Beginning of the week is:  trunc(sysdate, 'DAY')

>>add no of weeks schedule, (1-5)

Are you then wanting to addd 'weeks' to that?  if so, sumple math.
0
 
LVL 74

Accepted Solution

by:
sdstuber earned 2000 total points
ID: 37808353
this will give you Sunday of the current week

trunc(sysdate,'d')


this will give you Sunday of the current week plus one week

trunc(sysdate,'d') + 7

this will give you Sunday of the current week plus two weeks

trunc(sysdate,'d') + 14

this will give you Sunday of the current week plus five weeks

trunc(sysdate,'d') + 35


if you have number of weeks as a number parameter "n",  try this...

trunc(sysdate,'d') + (7 * n)
0
 
LVL 6

Author Comment

by:anumoses
ID: 37808355
select trunc(sysdate, 'DAY') from dual

TRUNC(SYSDATE,'DAY')
4/1/2012

So its sunday. Then I have to add 1(1 week) 2 (2 weeks) to 4/1/2012 and that has to be used in the query

select  a.department_id,a.payroll_id,
        a.schedule_date,a.start_time,a.start_ampm,
        a.end_time,a.end_ampm,a.total_hours,
        a.short_description,s.site_name,s.city_name
from off_duty a, sites s,blood_drives bd
where a.site_code = s.site_code(+)
and a.site_code = bd.site_code(+)
and a.schedule_date = bd.drive_date(+)      
and a.department_id = 5
and a.schedule_date = ????????
0
 
LVL 6

Author Comment

by:anumoses
ID: 37808358
OK got you. Will try
0
 
LVL 6

Author Comment

by:anumoses
ID: 37808514
select trunc(sysdate,'d'), trunc(sysdate,'d') + (7 * 1) from dual

TRUNC(SYSDATE,'D')      TRUNC(SYSDATE,'D')+(7*1)
4/1/2012                             4/8/2012

4/1/2012 is correct. But I have to get 4/7/2012 ( saturday)
0
 
LVL 6

Author Comment

by:anumoses
ID: 37808519
select trunc(sysdate,'d'), trunc(sysdate,'d') + (6 * 1) from dual

This is what I did.
0
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 37809108
>>This is what I did.

Does that get you what you want?

If so, don't forget to close out the question.

If not, what else do you need?
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 37809114
I suggest doing this...

select trunc(sysdate,'d'), trunc(sysdate,'d') + -1 + (7 * 1) from dual

if you try multiplying 6 for multiples of weeks you'll get the wrong result.
0
 
LVL 6

Author Closing Comment

by:anumoses
ID: 37810700
thanks
0

Featured Post

Independent Software Vendors: 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

I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

719 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