Query to get date range in Week

Hello all,
I wanted the get the results in terms of week like, if sysdate is 26/7/2007 Then
I have to get previous 7 weeks including the week where sysdate exists.
Results should come in this manner
23rd to 27th 1 week
16 - 20th July 2007 as 2nd week like this till 7 weeks
I have a query but it is not giving in the above manner
So please anybody can make a query as mentioned above.
Query:
SELECT TO_DATE(TO_CHAR(SYSDATE,'DD-MON-YYYY')) + ( ROWNUM - 6)+(ROWNUM+2)D,TO_DATE(TO_CHAR(SYSDATE,'DD-MON-YYYY')) + ( ROWNUM - 6)+(ROWNUM+2) R FROM DUAL CONNECT BY LEVEL < 6

What do you want?
-- A week
select sysdate, sysdate+7 from dual;
--A week from monday to sunday
select nexT_DAY(SYSDATE, 'MONDAY'), NEXT_day(sysdate-7, 'SUNDAY') FROM DUAL
BE CAREFUL MONDAY AND SUNDAY IF YOUR DDBB IS IN ENGLISH
select
nexT_DAY(SYSDATE, 'MONDAY'), NEXT_day(sysdate-7, 'SUNDAY'), TO_char(sysdate,'d'),
(sysdate -TO_char(sysdate,'d')) as firstone,
(sysdate + 7-TO_char(sysdate,'d') )as lastone
FROM DUAL
Message was edited by:
cth

Similar Messages

  • Query to get data for current week+13

    Hi Friends,
    I have two tables
    BACKLOG_WEEK_AFTER_ATP (LE)
    BACKLOG_ATP_GT_CW (RE)
    ** First I have to query whats the current week and year and it should come in this format ---- 2011-WK30
    columns in table BACKLOG_WEEK_AFTER_ATP are:
    ITEM_NUMBER      QUANTITY
    1N5418                 20
    1N5614                 30
    1N5806SM               10
    1N5811                  0
    2PFF6                  60columns in table BACKLOG_ATP_GT_CW are:
    ITEM_NUMBER     QUANTITY        YEAR_WEEK
    1N5418                30        2011-WK30
    1N5418                 5        2011-WK31
    1N5614                30        2011-WK32
    1N5806SM              30        2011-WK33
    1N5811                20        2011-WK32
    3EX473K1              20        2011-WK30My report should look like
    ITEM_NUMBER    2011-WK30  2011-WK31  2011-WK32  2011-WK33  ...............till 13th week
    1N5418                10         -5         -5         -5  ...............till 13t week
    1N5614                30         30          0          0  ................till 13th week
    1N5806SM              10         10         10         20  ................till 13th week
    1N5811                 0          0         20         20  ................till 13th week
    2PFF6                 60         60         60         60  ................till 13th week
    3EX473K1              20         20         20         20  ................till 13th weekTo get this report i have these conditions to keep in mind.
    1) If item_number not present in LE table and present in RE table then repeat what it is in RE table till 13th week
    2) If item_number not present in RE table and present in LE table then repeat what it is in LE table till 13th week
    3) If item_number present in LE and also present in RE table then do subtraction for RE - LE for that particular item_number till 13th week.
    4) If item_number is there in LE table but not present in RE table for current_week+1(today week comes as 29th week) then repeat the same which is there in LE table. If item is found in RE table for (example 32th week) then subtract RE -LE for that particular item_number
    Thanks in advance.
    Regards

    Hello,
    If you don't need the PIVOT display, then this may help you :
    with le as
    (select '1N5418' item_number, 20 quantity from dual union all
    select '1N5614' item_number, 30 quantity from dual union all
    select '1N5806SM' item_number, 10 quantity from dual union all
    select '1N5811' item_number, 0 quantity from dual union all
    select '2PFF6' item_number, 60 quantity from dual ),
    re as
    (select '1N5418' item_number, 30 quantity, '2011-WK30' year_week from dual union all
    select '1N5418' item_number, 5 quantity, '2011-WK31' year_week from dual union all
    select '1N5614' item_number, 30 quantity, '2011-WK32' year_week from dual union all
    select '1N5806SM' item_number, 30 quantity, '2011-WK33' year_week from dual union all
    select '1N5811' item_number, 20 quantity, '2011-WK32' year_week from dual union all
    select '3EX473K1' item_number, 20 quantity, '2011-WK30' year_week from dual
    row_gen as (
    select item_number, calc_year_week,
           row_number() over(partition by item_number order by calc_year_week) rn
    from
        (select le.item_number from le union select item_number from re) item,
        (select to_char(level*7+sysdate,'YYYY-"WK"WW') calc_year_week from dual connect by level<=13) week)
    select item_number, calc_year_week, calc_qty
    from row_gen, le, re
    where row_gen.item_number=le.item_number(+)
    and row_gen.item_number=re.item_number(+)
    and row_gen.calc_year_week=re.year_week(+)
    model
    partition by (row_gen.item_number)
    dimension by (rn)
    measures (calc_year_week, year_week, le.quantity le_qty,re.quantity re_qty,0 calc_qty )
    rules  (
    calc_qty[1]  =
        case when re_qty[cv()] is null then le_qty[cv()]
        when le_qty[cv()] is null then re_qty[cv()]
        else  re_qty[cv()]-le_qty[cv()]
    end,     
    calc_qty[rn>1] order by rn =
        case when re_qty[cv()] is null then calc_qty[cv()-1]
        else re_qty[cv()] - calc_qty[cv()-1]
        end           )
    order by 1,2;I am not sure this is the simplest way to do it, but the results seem to match your example.
    Regards,
    Sylvie
    Edited by: Troll35 on Jul 19, 2011 3:08 PM

  • SQL Query to get Date Range Values

    Hi,
    The database is Oracle11i.
    I am looking for a way to generate list of dates from a fixed date in the past (could be hardcoded) to current day (sysdate).
    That is, if the fixed date is 19 June 2011 and assuming that today is 24 June 2011 the SQL should be able to generate the
    following:-
    19-June-2011
    20-June-2011
    21-June-2011
    22-June-2011
    23-June-2011
    24-June-2011
    And the constraint is that I can't make any change to the database in question. I can only fire an SQL query (SELECT). No
    usage of time dimension kind of approach (time dimension is not available here) and no procedures, PL/SQL etc. Is there any way?
    Thanks

    Jaimeen Shah wrote:
    Hi,
    The database is Oracle11i.
    I am looking for a way to generate list of dates from a fixed date in the past (could be hardcoded) to current day (sysdate).
    That is, if the fixed date is 19 June 2011 and assuming that today is 24 June 2011 the SQL should be able to generate the
    following:-
    19-June-2011
    20-June-2011
    21-June-2011
    22-June-2011
    23-June-2011
    24-June-2011
    And the constraint is that I can't make any change to the database in question. I can only fire an SQL query (SELECT). No
    usage of time dimension kind of approach (time dimension is not available here) and no procedures, PL/SQL etc. Is there any way?
    Thanks
    SQL> def date_start = '13/11/2010'
    SQL> def date_end   = '22/11/2010'
    SQL> with
      2    data as (
      3      select to_date('&date_start', 'DD/MM/YYYY') date1,
      4             to_date('&date_end',   'DD/MM/YYYY') date2
      5      from dual
      6    )
      7  select to_char(date1+level-1, 'DD/MM/YYYY') the_date
      8  from data
      9  connect by level <= date2-date1+1
    10  /
    THE_DATE
    13/11/2010
    14/11/2010
    15/11/2010
    16/11/2010
    17/11/2010
    18/11/2010
    19/11/2010
    20/11/2010
    21/11/2010
    22/11/2010

  • Any Function Module to get date by passing week and year

    Hi,
       Is there any Function Module available to get date by passing week and year. For example, Week 24, Year 2005 and you get the date.
    Regards,
    Mira

    WEEK_GET_FIRST_DAY
    pass 'YYYYWW' (200524) to WEEK parameter it will give you the week start date
    Raja

  • Date range by week based on input parameters

    Afternoon folks -- I need to produce a report which will be displayed based on weeks.
    There are two input parameters: P_FROM_DATE and P_TO_DATE
    I need to find the date ranges in weeks starting on THURSDAY and ending on a WEDNESDAY. For example, if my P_FROM_DATE is 01-AUG-2012 and P_TO_DATE is 11-SEP-2012, I need to show the following weeks in this fashion:
    02-AUG-2012 - 08-AUG-2012
    09-AUG-2012 - 15-AUG-2012
    16-AUG-2012 - 22-AUG-2012
    23-AUG-2012 - 29-AUG-2012
    30-AUG-2012 - 05-SEP-2012
    06-SEP-2012 - 12-SEP-2012So, the idea is to start the first THURSDAY following the P_FROM_DATE and end on the WEDNESDAY preceding the P_END_DATE..
    Thanks!

    Hi,
    here's one way:
    WITH     params          AS
         SELECT  DATE '2012-08-01'     AS p_from_date
         ,     DATE '2012-09-19'     AS p_to_date
         FROM     dual
    ,     end_points     AS
         SELECT     TRUNC ( p_from_date + 4
                    , 'IW'
                    ) + 3          AS first_thursday
         ,     TRUNC ( p_to_date + 4
                    , 'IW'
                    ) - 5          AS last_wednesday
         FROM    params
    SELECT     first_thursday + (7 * (LEVEL - 1))     AS week_start_date
    ,     first_thursday + (7 * LEVEL) - 1     AS week_end_date
    FROM     end_points
    CONNECT BY     LEVEL     <= ( last_wednesday
                      + 1
                      - first_thursday
                      ) / 7
    ;TRUNC (dt) is the beginning of the ISO week that contains the DATE dt.
    The "magic number" 4 is used because the ISO week begins on Monday, 4 days later than your week begins, so
    TRUNC ( dt + 4
          , 'IW'
          )is the Monday in the same Thursday-Wednesday week as dt.

  • If I give 27 th week of 2007, can I get date range ( any FM is there ?)

    In my selection screen I am giving 27 th week and year 2007,
    I need to know know the date range ( monday to sunday ) for that week .
    For eg. if I give <b>1st</b> week and year <b>2007</b>,
    It should display 01/01/2007 to 07/01/2007 ( like DD/MM/YYYY ).
    is there any function module available to know this ?

    Hi sam ,
    just execute the code by giving date and  see if this works for u ,,
    check with input as 01/01/2007 i hope this will do ..
    parameters : P_DATE LIKE SCAL-DATE.
    DATA : HDATE LIKE SY-DATUM,
           LDATE LIKE SY-DATUM.
    data: WEEKno  LIKE  SCAL-WEEK,
          refmonDAY  LIKE  SY-DATUM,
          REFSUNDAY  LIKE  SY-DATUM.
       CALL FUNCTION 'GET_WEEK_INFO_BASED_ON_DATE'
        EXPORTING
          DATE          = p_date
        IMPORTING
          WEEK          = weekno
          MONDAY        = refmonday
          SUNDAY        = refsunday.
          write:/ 'weeknumber', weekno, 
          write:/ 'monday' ,refmonday.
          write:/  'sunday', refsunday.
    see if this works for u ..
    can you can tell me ur input criteria as how u r passing the date if u r query is not completed ..
    regards,
    vijay

  • How to get data for current week and previous week using customer exit in Bex.

    Hi everyone,
    I have a scenario in which I need to display data for current week and previous week (based on "sy_datum" the program has to calculate current week and previous week) in Bex using  Customer exit. I have created one variable in Bex Query Designer and I have written code for the variable in CMOD. But it is not working fine, (I know that we can do the same by using offset value in Bex). Can some one guide me how to achieve my requirement using customer exit.
    Thanks in Advance,
    G S Ramanjaneyulu.

    Hi krishna,
    Thanks for your quick reply, can you have a look at my code,
    case i_vnam.
    WHEN 'ZPWK_CWK'.
    ranges : pre_week for sy-datum.
    data : start_date type DATS,
           end_date TYPE dats .
    ************FM TO GET FIRST DATE OF CURRENT WEEK ************************
    CALL FUNCTION 'BWSO_DATE_GET_FIRST_WEEKDAY'
      EXPORTING
        DATE_IN  = sy-datum
      IMPORTING
        DATE_OUT = start_date.   " WEEK FIRST DATE
    end_date = START_DATE + 6.   " WEEK LAST DATE
    END_DATE   = START_DATE - 1.   " PREVIOUS WEEK END DATE
    START_DATE = START_DATE - 7.   " PREVIOUS WEEK START  DATE
    **********PREVIOUS WEEK DATES IN PRE_WEEK******************
    pre_week-SIGN   = 'I'.
    pre_week-option = 'BT'.
    pre_week-LOW    = START_DATE.
    pre_week-HIGH   = END_DATE.
    APPEND  pre_week.
    CLEAR : START_DATE,END_DATE.
    endcase.
    Regards,
    G S Ramanjaneyulu.

  • Query problem with date range

    I have a query that needs to pull data between a date range.
    I've tried several things and nothing seems to work.
    Any help would be greatly appreciated.
    Here's the code:
    <cftransaction>
    <cfquery name="QryFollowUp"
    datasource="NBProdReports">
    SELECT TblContractInfo_SubMenuTable.User_ID,
    TblContractInfo_SubMenuTable.Contract_Number,
    TblContractInfo_SubMenuTable.Transaction_Type,
    TblContractInfo_SubMenuTable.Notes,
    TblContractInfo_SubMenuTable.Num_Checks_Trans,
    TblMasterTrans.Date_Opened
    from TblContractInfo_SubMenuTable ,tblMasterTrans
    WHERE Transaction_Type = 'FollowUp'
    And TblContractInfo_SubMenuTable.Task_Number =
    tblMasterTrans.Task_Number
    And TblMasterTrans.Date_Opened BETWEEN #form.StartDate# AND
    #form.EndDate#
    ORDER BY TblMasterTrans.Date_Opened ASC,
    TblContractInfo_SubMenuTable.User_id ASC
    </cfquery>
    </cftransaction>

    Any help would be greatly appreciated.
    Ok, why are you using a <cftransaction...> around a
    single select query?
    It should be unnecessary.
    This is probably not helpful to your original question. There
    is
    nothing obviously wrong with your query at least to my glance
    through.
    Thus this important question, the one without which you are
    unlikely to
    get any helpful advice, "How does this not work?" Error
    Messages? No
    Data? Wrong Data? Serves you coffee instead of tea?
    It would also probably be helpful to know how your date data
    is
    represented in the database and the form controls, depending
    on what
    your difficulties are.

  • Getting date range in Find User Form

    Hello experts,Actually my goal is to get list of users having termination date within date range.But here my problem is when i added this business logic in Find user form which does loop on all users i was unable to get the list of users having termination within date range as the termination date of user object is string.
    By gettting problem in the above way we tried to query date attribute of the task property of user object which is set with the value of termintion date when the user is created.The task property code is given below
    <Properties>
    <Property name='tasks'>
    <List>
    <Object name='Conseco Account Termination Date'>
    <Attribute name='date' value='01/10/2008'/>
    <Attribute name='task' value='Conseco Account Termination Date'/>
    </Object>
    <Object name='Sunset Date'>
    <Attribute name='date' value='2/22/2008'/>
    <Attribute name='task' value='Sunset Date'/>
    </Object>
    </List>
    </Property>
    </Properties>
    Could anyone help me in referring the date attribute of 'Conseco Account Termination Date' property

    Because the date is stored as a string, you'll need to use a different format. Use yyyy/MM/dd. You can use the stringToDate and dateToString methods.

  • Query for getting data for every quarter for financial year

    Hi,
    My problem is I need to get the data for every quarter for financial year and also I need data for every week for financial year.
    For example for financial year 2012-13, Apr2012 to Jun2012 would be Q1, Jul2012 to Sep2012 would be Q2 and so on. Total 8quarters should come upto Apr2013.
    In the same way  1st apr 2012 to 7th apr 2012 would be week1, 8th apr to 15th apr would be week2 and son on. How to write a query for this scenario in oracle. Can anybody help me on this. very urgent..
    Thanks in advance.

    lakmesri wrote:
    Hi,
    My problem is I need to get the data for every quarter for financial year and also I need data for every week for financial year.
    For example for financial year 2012-13, Apr2012 to Jun2012 would be Q1, Jul2012 to Sep2012 would be Q2 and so on. Total 8quarters should come upto Apr2013.
    In the same way  1st apr 2012 to 7th apr 2012 would be week1, 8th apr to 15th apr would be week2 and son on. How to write a query for this scenario in oracle. Can anybody help me on this. very urgent..
    Thanks in advance.
    How can you get 8 quarters within a year ? I'b be concerned here.
    lakmesri wrote:
    Hi,
    In the same way  1st apr 2012 to 7th apr 2012 would be week1, 8th apr to 15th apr would be week2 and son on. How to write a query for this scenario in oracle. Can anybody help me on this. very urgent..
    Thanks in advance.
    First, that question is really not clearly asked. Second how could it be urgent ? You even did not tell us your Oracle version, did not show any tables descr, output sample nor any effort on your side to work on.
    Nicolas.

  • Get dates of last week - Please Help !

    Hi All,
    I have to make a query for retrieving the data for the last one week from a table say "Orderdata".
    So can anybody please tell me how to retrieve date of last weak from the current date. I mean if current date is 12/08/2004 (mm/dd/yyyy) then I would be needing date as :--
    12/01/2004 (mm/dd/yyyy) to 12/07/2004 (mm/dd/yyyy).
    To more clear, here is the query that am using :
    select * from orderdata where orderdate between 12/01/2004 AND 12/07/2004
    I know I would be needing java.sql.timestamp class to set date . but it is the last thing to do .
    First I have to get date of last weak...........
    Here is the code----------that i have just start to write ..
    Calendar cal;
    TimeZone tz;
    String estTimezone="GMT-05:00";
    tz=TimeZone.getTimeZone(estTimezone);
    cal=new GregorianCalendar(tz);
    cal.setTimeZone(tz);
    String currentdate=String.valueOf(cal.get(Calendar.MONTH)+1);
    currentdate+="/"+String.valueOf(cal.get(Calendar.DAY_OF_MONTH)-1);
    currentdate+="/"+String.valueOf(cal.get(Calendar.YEAR));
    out.println(currentdate);And assume if current date is 12/1/2004 (mm/dd/yyyy) then subtracting -1 form the current date will give 12/00/2004 so not getting the correct result .
    Hope it is clear to all................
    Please Help !
    amitindia

    Hi All,
    Thanks chirag813 for your coding. and thanks to all.
    By the way I have to change time in EST and also required start date and end date of last weak. So my final coding is as:
    Please have a look into the code and tell me whether the code is correct / fine or not.
    Do I need to call the getInstance() method in my code as you (chirag813) have put in your code
    Calendar calendar = Calendar.getInstance();
    Is my code fine ?
    Please Answer..................
    String startdate;
    String enddate;
    Calendar cal;
    TimeZone tz;
    String estTimezone="GMT-05:00";
    // is this line correct to get startdate
    SimpleDateFormat sdfStartdate= new SimpleDateFormat("yyyy-MM-dd 00:00:00");
    // is this line correct to get enddate
    SimpleDateFormat sdfEnddate= new SimpleDateFormat("yyyy-MM-dd 23:59:59");
    tz=TimeZone.getTimeZone(estTimezone);
    cal=new GregorianCalendar(tz);
    cal.setTimeZone(tz);
    cal.add(Calendar.DATE,-7);
    startdate=sdfStartdate.format(cal.getTime());
    cal.add(Calendar.DATE,6);
    enddate=sdfEnddate.format(cal.getTime());
    Timestamp t1=Timestamp.valueOf(startdate);
    Timestamp t2=Timestamp.valueOf(enddate);
    out.println(t1);
    out.println("<br>"+t2);
    And finally I have used Timestamp class to change the date (String) to Timestampt.
    Thanks !
    amitindia
    SCJP 1.2

  • Oracle SQl query to find date range based on another cloumn value

    Hi Folks,
    I want to extract records for the employees who have consecutive vacation/leave from a table. If an emp has vacation of 3 days (MON-WED), the table contains 3 distinct records for him,
    e.g. My table contains records as shown below.
    EmpName Paycode ApplyDate Amt. of Hrs
    emp1 vacation 5/1/2010 8
    emp1 vacation 5/2/2010 8
    emp1 vacation 5/3/2010 8
    I am trying to get the output like this...
    Emp Name Paycode Leave Start Date Leave End Date TotalHrs
    emp1 vacation 5/1/2010 5/3/2010 24
    Note: If the smae emp has sets of vacation in another month, that should come as a separate record with start date and end date(last date of vacation for that set).
    I have a query which does not return any rows. Any help to repair this query or any better one would be of great help.
    ==================================================================
    WITH vpt AS (
    select personnum as empname, paycodename as paycode, applydate, timeinseconds/3600 as numhours from VP_TOTALS
    where applydate between to_date('05/01/2010','MM/DD/YYYY') AND to_date('12/31/2010','MM/DD/YYYY')
    AND paycodename in ('US-Vacation','US-Bereavement','US-Sick','US-Jury Duty')
    select
    empname,
    paycode,
    min(applydate) as startdate,
    max(applydate) as enddate,
    sum(numhours) as totalhours
    from (
    select
    empname,
    paycode,
    applydate,
    numhours,
    -- number the blocks sequentially
    sum(is_block_start) over (partition by empname, paycode order by applydate) as block_num
    from (
    select
    empname,
    paycode,
    applydate,
    numhours,
    -- Mark the start of each block
    case
    when applydate = prev_applydate + 1 then 0 else 1 end as is_block_start
    from (
    select
    empname,
    paycode,
    applydate,
    numhours,
    lag (applydate) over (partition by empname, paycode order by applydate) prev_applydate
    from vpt
    group by empname, paycode, block_num
    ===================================================================
    Thanks,
    Maha

    Hi Dear,
    Can I do reverse I mean I can get output as your question from your output as below:
    I have this table
    FID      STARTD ATE END DATE
    1 01-MAY-10 03-MAY-10
    1 09-MAY-10 11-MAY-10
    1 03-JUN-10 04-JUN-10
    2 03-JUN-10 04-JUN-10
    2 04-AUG-10 04-AUG-10
    2 06-AUG-10 06-AUG-10
    I want like this.
    FID FDATE
    1 01-MAY-10
    1 02-MAY-10
    1 03-MAY-10
    1 09-MAY-10
    1 10-MAY-10
    1 11-MAY-10
    1 03-JUN-10
    1 04-JUN-10
    2 03-JUN-10
    2 04-JUN-10
    2 04-AUG-10
    2 06-AUG-10
    And:
    How can i get date wise entry from Joining date to relieving date like..
    FID      START DATE END DATE
    1 01-MAY-10 03-MAY-12
    1 09-MAY-10 11-MAY-11
    2 04-AUG-10 04-AUG-11
    I want like this.
    FID FDATE
    1 01-MAY-10
    1 03-MAY-10
    1 04-MAY-10
    1 05-MAY-10
    1 16-MAY-10
    1 17-MAY-10
    1 08-May-10
    1 09-May-10
    1 03-May-12
    Can you please help me.
    Thanks,
    Edited by: 978452 on Dec 24, 2012 12:02 AM

  • Single query to get data from different databases

    i need to capture certain fields from certain tables in database 1 and certain fields from certain tables in database 2 into one file using a single SQL statement.
    i tried searching on the net
    i found that dblinks can help
    but iam not sure if ill be able to create dblinks in my situation which is:
    i need to get data from oracle to be copied to mysql
    this is not a replication acitivity, but i need certain fields from one database and certain from the other
    so what iwas thinking is, if i use an sql query to get all the fields (i need around 40) from the different oracle databases and create a singlefile with one insert per select, i can then read that file into mysql
    instead of creating multiple sql queries for each table and creating separate files and eventually separate tables in mysql.
    can anyone help me here?
    or maybe suggest another approach.
    thanks

    Hi,
    I think dblink is the only option available to get data from different databases. It will work for your case too.
    CREATE DATABASE LINK db_link CONNECT TO user_name IDENTIFIED BY  password USING 'instance_name'you must have the system privilege 'create database link' to create db links. This way you can get the required data and put it in a table in oracle. But i dont know how to put this data from oracle table to Mysql.
    HTH
    Muneer

  • How to get date range of Current week

    Hi Gurus,
    I need to create report of current(this) week manual bills created by one user. I have date Field called CREAT_DATE.Based on this date column i need to create report.
    Could anybody help to get this query.
    Example:
    select .....
    from ....
    where
    CREAT_DATE
    Thank You
    Vikram

    It kind of depends on your definition of "current week". If you mean something like the last 7 days, then
    SELECT columns
    FROM table
    WHERE creat_date BETWEEN TRUNC(sysdate - 7) and TRUNC(sysdate +1)would do it.
    If you mean Monday until today, then:
    SELECT columns
    FROM table
    WHERE creat_date BETWEEN NEXT_DAY(TRUNC(sysdate - 7), 'MONDAY') and TRUNC(sysdate +1)Read up on the various date functions for other possibilities.
    TTFN
    John

  • Query for a Date Range

    Hi folks,
    hope everyone had a good weekend. Have a problem at hand and hoping to find a solution. Here is what I need to do. I need to find out the following based on Dates.
    Currently, we have Students who pay certain kinds of fees and that is detrmined based on their Fee Codes. I will listing the table structure in a bit.
    Query 1:
    1. I need to find out Students who did not have a Fee Code back in September 1st, 2009 and had a Fee Code on September 1st, 2010.
    Query 2:
    2. Find out students who had a Fee Code back in September 01st, 2009 and do not have a Fee Code in September 01,2010.
    Now, by saying that a Student no longer has a Fee Code in September 01,2009/2010, it's not just the fact that record does not exist but also that there is an Expiry Date. So, basically, when a new record is created in the table, the previous record's GRAD_EXP_EFF_DATE gets stamped with SYSDATE.
    Table GRAD_FEE_STRUCTURE_HIST
    GRAD_STU_ID        NOT NULL  VARCHRA2(6)
    GRAD_STU_FEE_CODE  NOT NULL  VARCHAR2(6)
    GRAD_EFF_FEE_DATE  DATE
    GRAD_EXP_FEE_DATE  DATE
    GRAD_CREATE_DATE   DATE
    GRAD_CREATE_USERID VARCHAR2(10)Any help is appreciated. I am using Oracle 9i.

    Hi,
    Try something like this:
    SELECT       grad_stu_id
    FROM       grad_fee_structure_hist
    GROUP BY  grad_stu_id
    HAVING       COUNT ( CASE
                      WHEN  DATE '2010-09-01'  BETWEEN  grad_eff_fee_date
                                               AND        grad_exp_fee_date
                    THEN  1
                END
              )     > 0
    AND       COUNT ( CASE
                      WHEN  DATE '2009-09-01'  BETWEEN  grad_eff_fee_date
                                               AND        grad_exp_fee_date
                    THEN  1
                END
              )     = 0
    ;If a NULL grad_fee_exp_date means that the row is currently in force, then use something like
    NVL ( grad_fee_exp_date
        , DATE '9999-12-31'
        )instead of the raw date.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements) and the results you want from that data. Explain how you get those results from that data, giving specific examples.
    Always say what version of Oracle you're using.
    Edited by: Frank Kulash on Sep 13, 2010 11:08 AM
    Changed date comparisons to BETWEEN.

Maybe you are looking for

  • SSRS to Oracle 64 bit vs 32 bit patch

    I have one server running Windows Server 2003 R2 and SQL Server 2008 x64 with Reporting Services. I am creating a report from within BIDS which uses the 32 bit (x86) directory. This report points to an Oracle 10g 10.2.0.3.0 database on another server

  • Package loading issue in Business Connector - Urgent Production deployment

    Hi, I created few additional flows in the Dev BC server and published them onto the Prod BC server. From Prod server, I tried installing them using Install Inbound release link. But nothing is happening after the link is clicked, i.e neither i get an

  • Append,Append_values

    Hi Guys, Can you people distingush between conventional insert and direct path insert? it may help me to understand oracle hints.....

  • Safari unexpectedly quits

    I recently upgraded to tiger and I've had a few problems, and I would like some help with this one. When I am trying to attach a file to an email on the aim mail webpage everything works fine untill I click on the "choose file" button on the page the

  • Reading windows user id and computer name

    I am using servlet and jsp's in my web application. I want to read clients computer name and their windows userId in jsp. How I can do this? Thanks, Reddy