Start date and end date

We have two tables

Product and Transaction

We have records produced like this

Product

ID Startdate Enddate Loc Grp
ABC 101 x 1/1/2009-31/03/09
102 abc x 1/1/2009-31/03/09

These details need to be updated in the table of transactions in a way like this

Transaction

ID Grp Loc weekly
ABC 101 x 1/1/2009 (added 7 days)
ABC 101 x 8/1/2009
ABC 101 x 15/1/2009
ABC 101 x...
ABC 101 x...
101 x upto 31/3 abc

ABC 102 x 1/1/2009
ABC 102 x 8/1/2009
ABC 102 x 15/1/2009
ABC 102 x...
ABC 102 x...
102 x upto 31/3 abc


Please help me

Thanks in advance

Try this:

SQL>WITH t AS
  2       (
  3          SELECT 101 AS ID, 'abc' AS grp, 'x' AS loc, DATE '2009-1-1' AS startdate, DATE '2009-3-31' AS enddate
  4            FROM DUAL
  5          UNION ALL
  6          SELECT 102, 'abc', 'x', DATE '2009-1-1', DATE '2009-3-31'
  7            FROM DUAL)
  8  SELECT   ID, grp, loc, startdate + (l - 1) * 7 AS weekly
  9      FROM t,
 10           (SELECT     LEVEL AS l
 11                  FROM DUAL
 12            CONNECT BY LEVEL <= 100)
 13     WHERE l <= (SELECT MAX(enddate - startdate)
 14                   FROM t) / 7 + 1
 15  ORDER BY ID, grp, loc, weekly;

        ID GRP L WEEKLY
---------- --- - --------
       101 abc x 01.01.09
       101 abc x 08.01.09
       101 abc x 15.01.09
       101 abc x 22.01.09
       101 abc x 29.01.09
       101 abc x 05.02.09
       101 abc x 12.02.09
       101 abc x 19.02.09
       101 abc x 26.02.09
       101 abc x 05.03.09
       101 abc x 12.03.09
       101 abc x 19.03.09
       101 abc x 26.03.09
       102 abc x 01.01.09
       102 abc x 08.01.09
       102 abc x 15.01.09
       102 abc x 22.01.09
       102 abc x 29.01.09
       102 abc x 05.02.09
       102 abc x 12.02.09
       102 abc x 19.02.09
       102 abc x 26.02.09
       102 abc x 05.03.09
       102 abc x 12.03.09
       102 abc x 19.03.09
       102 abc x 26.03.09

HTH, Urs

Tags: Database

Similar Questions

  • Find the period by subtracting the start time and end

    Version: 11.2

    I am not a SQL expert.

    I'm trying to subtract the start and end time and find the difference between these two times.

    In the example below, the difference between the value of start_time and end_time is approximately 52 minutes (18:15 to 19:07)

    I tried a few tricks to find the difference below. But it did not work.

    SQL > create table t (start_time date, date of end_time);

    Table created.

    SQL > desc t

    Name                                                              Null?    Type

    ----------------------------------------------------------------- -------- ---------------------

    START_TIME                                                                 DATE

    END_TIME                                                                   DATE

    SQL > insert into values t (to_date (24 June 2013 18:15:42 ',' DD/MONTH/YYYY HH24:MI:SS'), to_date (24 June 2013 19:07:54 ',' DD/MONTH/YYYY HH24:MI:SS'));))

    1 line of creation.

    SQL > commit;

    Validation complete.

    SQL >

    SQL >

    SQL > select * from t;

    START_TIME, END_TIME

    --------------------     --------------------

    24 June 2013 18:15:42 24 June 2013 19:07:54

    -Trying to find the difference of Start_Time and End_Time

    SQL > select end_time-start_time in t;

    END_TIME-START_TIME

    -------------------

    . > 03625 than signifie.03625?

    -More than failure tent

    SQL > select to_number(end_time-start_time)/60 t.

    TO_NUMBER(END_TIME-START_TIME)/60

    ---------------------------------

    .000604167

    SQL > select to_number(end_time-start_time) * 24/60 t.

    TO_NUMBER(END_TIME-START_TIME) * 24/60

    ------------------------------------

    .0145

    SQL > select to_number(end_time-start_time) * 60 * 60 t.

    TO_NUMBER(END_TIME-START_TIME) * 60 * 60

    ------------------------------------

    130,5

    SQL > select to_number(end_time-start_time) * 60 * 60/24 t;

    TO_NUMBER(END_TIME-START_TIME) * 60 * 60/24

    ---------------------------------------

    5.4375

    Hello

    Search Date arithmetic in the manual of the SQL language.

    When you subtract one DATE from another, the result is the number of days between them.  .03625 days is a little more de.033333333... days, which is 1/30 a day, or 48 minutes.

    If you want the difference in hours, multiply by the number of hours per day, which is 24.

    If you want the difference in minutes, multiply by the number of minutes per day, or 24 * 60.

    If you want the difference expressed in days hours: minutes: seconds, then you are better off conversion (at least) one of the DATEs in TIMESTAMP; then, when you subtract them, you will get the difference as an INTERVAL DAY TO SECOND, which appears as

    + 05:06:37.000000 000000000

    This means that 0 days, 5 hours, 6 minutes, 37 seconds.

  • by the numbers, how can I convert a start time and end in hours time

    I convert my files to Excel, and no to not translate my formulas.

    I have a start time, end time, and hours, what formula should I use to have hours to calculate?

    Thanks for any help

    by the numbers, you can perform mathematical operations on time like this... assuming they are valid values for date/time...

    Assuming that one time is in cell A1 and the other is in A2, you can get the difference like this:

    = dur2hours(a1-a2)

  • Start time and end of timestamp time calculation

    Hi all

    I have an entry below,

    Channel_number GPS_TIME
    581513-05-2013 18:56:46.410000
    581513-05-2013 18:56:47.410000
    581513-05-2013 18:56:48.410000
    581513-05-2013 18:56:49.410000
    578013-05-2013 18:56:49.510000
    578013-05-2013 18:56:50.410000
    578013-05-2013 18:56:51.410000
    581513-05-2013 18:56:51.510000
    581513-05-2013 18:56:52.410000

    I'm trying to get the result as below,

    CHANNEL_NUMBER BEGIN_TIME End_time
    581513-05-2013 18:56:46.41000013-05-2013 18:56:49.410000
    578013-05-2013 18:56:49.51000013-05-2013 18:56:51.410000
    581513-05-2013 18:56:51.51000013-05-2013 18:56:52.410000

    Please, help me find it.

    Thank you all

    with

    the_data as

    (select 5815 channel_number to_timestamp ('2013-05-13 18:56:46.410000 ',' yyyy-mm-dd hh24:mi:ss.ff') gps_time of all the double union)

    Select 5815, to_timestamp ('2013-05-13 18:56:47.410000 ',' yyyy-mm-dd hh24:mi:ss.ff') of all the double union

    Select 5815, to_timestamp ('2013-05-13 18:56:48.410000 ',' yyyy-mm-dd hh24:mi:ss.ff') of all the double union

    Select 5815, to_timestamp ('2013-05-13 18:56:49.410000 ',' yyyy-mm-dd hh24:mi:ss.ff') of all the double union

    Select 5780, to_timestamp ('2013-05-13 18:56:49.510000 ',' yyyy-mm-dd hh24:mi:ss.ff') of all the double union

    Select 5780, to_timestamp ('2013-05-13 18:56:50.410000 ',' yyyy-mm-dd hh24:mi:ss.ff') of all the double union

    Select 5780, to_timestamp ('2013-05-13 18:56:51.410000 ',' yyyy-mm-dd hh24:mi:ss.ff') of all the double union

    Select 5815, to_timestamp ('2013-05-13 18:56:51.510000 ',' yyyy-mm-dd hh24:mi:ss.ff') of all the double union

    Select 5815, to_timestamp (' ' 2013-05-13 18:56:52.410000 ',' yyyy-mm-dd hh24:mi:ss.ff ") of the double

    )

    Select channel_number, begin_time, end_time

    from (select gr,

    channel_number,

    FIRST_VALUE (gps_time) on begin_time (gr stopped by gps_time partition),

    FIRST_VALUE (gps_time) on end_time (gr stopped by gps_time desc partition),

    ROW_NUMBER() on rn (gr stopped by gps_time partition)

    from (select channel_number, gps_time,

    ROW_NUMBER() on row_number() (order of gps_time) - on the gr (partition by order of gps_time channel_number)

    of the_data

    )

    )

    where rn = 1

    begin_time order

    CHANNEL_NUMBER BEGIN_TIME END_TIME
    5815 13 MAY 13 06.56.46.410000000 PM 13 MAY 13 06.56.49.410000000 PM
    5780 13 MAY 13 06.56.49.510000000 PM 13 MAY 13 06.56.51.410000000 PM
    5815 13 MAY 13 06.56.51.510000000 PM 13 MAY 13 06.56.52.410000000 PM

    Concerning

    Etbin

    Post edited by: Etbin me or Apex we missed something in the original post

  • 39L4363D - cannot set the record time of beginning and end of filling time

    Hello

    I have a problem with my 39L4363DG tv (software 7.1.90.34.01.1).

    I'm not able time of filling time of beginning and end of record setting as described in the [Manual | http://www.toshiba-om.net/LCD/PDF/English/L4363-323950-English.pdf] on page 51. The menu item "padding-start" and 'end padding time' are disabled?

    Can someone help me and give me advice on how to solve it?

    Hello

    The charging time can be set for the scheduled recording.

    There is also a priority planning
    If the regular time intervals are ensuites to each other and there is more than one minute between the time of the end of the annex i and the next scheduled start time, scheduled recording will be performed correctly.

    When + start time of filling + and + hour of end padding + are value, the start time and end time more is the time the extra minutes.

    If planning time overlap, priority will be given to the scheduled recording starts first.
    When the scheduled recording that began the first ends, recording will switch to the next regular program.
    At that time, according to how much programming time to overlap, the section from the beginning of the next regular program is not registered.

  • Start and end date of week 1-5 a month

    I wanted to print the date of beginning and end of the week for a given month.  If the month last_week overlaps the next month, I don't want to print the week5. If the week5 overlap with next month, then it must be printed.

    SELECT

    TRUNC (to_date(:P_DATE,'MM/DD/YYYY'), 'IW') 'SW1', / * start of week 1 * /.

    TRUNC (TO_DATE (: P_DATE, "MM/DD/YYYY '") + 6, 'IW')-1 'EW1', / * end of week you 1 * /.

    NEXT_DAY (trunc (to_date(:P_DATE,'MM/DD/YYYY'), 'IW'), 'Monday') 'SW2 '.

    NEXT_DAY (TRUNC (TO_DATE (: P_DATE, "MM/DD/YYYY") + 6, 'IW'), 'Sunday') 'EW2. "

    NEXT_DAY (NEXT_DAY (trunc (to_date(:P_DATE,'MM/DD/YYYY'), 'IW'), 'Monday'), 'Monday') "SW3."

    NEXT_DAY (NEXT_DAY (TRUNC (TO_DATE (: P_DATE, "MM/DD/YYYY") + 6, 'IW'), 'Sunday'), 'Sunday') 'EW3. "

    NEXT_DAY (NEXT_DAY (NEXT_DAY (trunc (to_date(:P_DATE,'MM/DD/YYYY'), 'IW'), 'Monday'), 'Monday'), 'Monday') "SW4".

    NEXT_DAY (NEXT_DAY (NEXT_DAY (TRUNC (TO_DATE (: P_DATE, "MM/DD/YYYY") + 6, 'IW'), 'Sunday'), 'Sunday'), 'Sunday') 'EW4. "

    NEXT_DAY (NEXT_DAY (NEXT_DAY (NEXT_DAY (trunc (to_date(:P_DATE,'MM/DD/YYYY'), 'IW'), 'Monday'), 'Monday'), 'Monday'), 'Monday') 'SW5. "

    NEXT_DAY (NEXT_DAY (NEXT_DAY (NEXT_DAY (TRUNC (TO_DATE (: P_DATE, "MM/DD/YYYY") + 6, 'IW'), 'Sunday'), 'Sunday'), 'Sunday'), 'Sunday') 'EW5.

    FROM DUAL;

    SW1 EW1 SW2 EW2 SW3 EW3 SW4 EW4 SW5 EW5
    29/12/201404/01/201505/01/201511/01/201512/01/201518/01/201519/01/201525/01/201526/01/201501/02/2015

    Is it possible to get it without using the next_day() several times for each week and to limit the accumulation of the week last in a month.

    Check my last answer. And if this isn't what you need, then the expected results for each month in 2015.

    SY.

  • Can I add start and end dates to flex in WCS assets?

    Hi all

    I have to add the start and end dates to my flex belt and make it visible on the plus edition + inspect mode. For the Fund, it is STANDARD, but I have an obligation to do so for other assets that is not active promotion.

    Is there any doc/blog I can do? Help, please.

    Hi Avi.

    Dates of start and end standards are OOTB field in the metadata of the asset. So they you must set the cs.sitepreview property in the file futuretense.ini in the 'management '.

    CS.sitepreview = ContentManagement

    You can check out the documentation for more details about this property: futuretense.ini - 11 g Release 1 (11.1.1.8.0)

    If you need something different, maybe you need create your own attributes Start Date and end using types date: Data Design: active models - 11 g Release 1 (11.1.1.8.0)

    Kind regards

    Raul.

  • Primavera P6 API - start and end dates of the activity in the secondary reference scenario

    How to seek early and dates of activity in the secondary database or tertiary reference end? There are areas of activities and methods provided in planning extraction and primary base line project (active class getBaseline1StartDate(), getBaseline1FinishDate) but can't find any secondary data or tertiary basis even if we show them in details the activity in the Primavera. I use Primavera integration API version 8.2.

    Use the BaselineProjectHelper class to get a list of all the base lines for a given project.  Go through the list looking for basic lines you are interested in.

    Once you have basic interest projects, pull a list of ongoing project activities.

    Browse the list of activities tearing you start and end dates.

    Call the method on each of you loadBaselineActivity of reference projects for the departure of the referenced activity and end dates.

    For performance, seek assistance loadBaselineActivities to reduce database queries.

    V/r,

    Gene

  • Simple validation on the start and end dates

    Apex 4.2

    I'm trying to create a script of validation on my start date and end date. A simple validation indicating the start date must be less than the end date. Because apex deals my fields of date as a string, using an expression of pl/sql as P101_START_DATE < = P101_END_DATE does not work. This may seem like an easy question, but I'm unable to create this simple validation. Any help would be greatly appreciated. Thanks in advance!

    Take a look how the TO_DATE plsql function works... ie... to_date(:P101_START_DATE,'mm-DD-yyyy')<=to_date(:P101_END_DATE,'mm-dd-yyyy'),>

  • Planning of the attributes to dates 11.1.2.2 and start and end in a cell

    Hello. In planning 11.1.2.2., can I use dimensions of the attribute, like I would in a cube Essbase BSO?

    Also can I enter a start date and an end date entry in two different account (for example, start_date and end_date) members?

    Thank you


    Hello

    Yes, I think you can use it.

    And you can change the account date data type member. Then use these accounts in the planning Web form. Form will give you the opportunity to select the Date...

    VB...

  • Calculate the start and end date in Connect By - during Hirerchy changes

    / * Formatted 05/20/2013 09:53 (PS5 v5.115.810.9015) * /.



    Oracle Database 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production

    Hello, can you please help me or guide me in the calculation of the dates of beginning and end to the underside of logic

    I want to calculate the Hirerchy Manager to the Agent.
    Then under query works fine and its giving me the expected results
    But when there is a change in the Hirerchy Manager or manager gets promoted
    Then I need to calculate the start date and end date.
    CREATE TABLE PERSON_DTL
    (
      SID                 VARCHAR2(10 BYTE),
      EMP_MGRS_ID         VARCHAR2(10 BYTE),
      START_EFFECTIVE_DT  DATE,
      END_EFFECTIVE_DT    DATE
    );
    
    Insert into PERSON_DTL
       (SID, EMP_MGRS_ID, START_EFFECTIVE_DT, END_EFFECTIVE_DT)
     Values
       ('M100', 'M107', TO_DATE('05/20/2013 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('12/31/9999 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into PERSON_DTL
       (SID, EMP_MGRS_ID, START_EFFECTIVE_DT, END_EFFECTIVE_DT)
     Values
       ('M101', 'M102', TO_DATE('01/01/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('05/18/2013 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into PERSON_DTL
       (SID, EMP_MGRS_ID, START_EFFECTIVE_DT, END_EFFECTIVE_DT)
     Values
       ('A100', 'M100', TO_DATE('01/01/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('12/31/9999 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into PERSON_DTL
       (SID, EMP_MGRS_ID, START_EFFECTIVE_DT, END_EFFECTIVE_DT)
     Values
       ('M100', 'M101', TO_DATE('01/01/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('05/18/2013 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into PERSON_DTL
       (SID, EMP_MGRS_ID, START_EFFECTIVE_DT, END_EFFECTIVE_DT)
     Values
       ('M107', 'M102', TO_DATE('05/20/2013 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('12/31/9999 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into PERSON_DTL
       (SID, EMP_MGRS_ID, START_EFFECTIVE_DT, END_EFFECTIVE_DT)
     Values
       ('M102', 'M103', TO_DATE('01/01/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('12/31/9999 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into PERSON_DTL
       (SID, EMP_MGRS_ID, START_EFFECTIVE_DT, END_EFFECTIVE_DT)
     Values
       ('M103', 'M104', TO_DATE('01/01/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('12/31/9999 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into PERSON_DTL
       (SID, EMP_MGRS_ID, START_EFFECTIVE_DT, END_EFFECTIVE_DT)
     Values
       ('A101', 'M105', TO_DATE('01/01/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('12/31/9999 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into PERSON_DTL
       (SID, EMP_MGRS_ID, START_EFFECTIVE_DT, END_EFFECTIVE_DT)
     Values
       ('M105', 'M106', TO_DATE('01/01/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('12/31/9999 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
    COMMIT;
    SELECT   CONNECT_BY_ROOT (b.sid) agent_sid,
                 TRIM (
                    LEADING ',' FROM    SYS_CONNECT_BY_PATH (b.sid, ',')
                                     || ','
                                     || b.emp_mgrs_id
                 )
                    PATH,
                 START_EFFECTIVE_DT Start_dt,
                 END_EFFECTIVE_DT End_dt
          FROM   PERSON_DTL b
         WHERE   CONNECT_BY_ISLEAF = 1
    START WITH   sid IN ('A101', 'A100')
    CONNECT BY   PRIOR b.emp_mgrs_id = b.sid
    This is the results that i am getting now.
    
    AGENT_SID    PATH                       START_DT    END_DT
    
    A100    A100,M100,M101,M102,M103,M104    1/1/2010    12/31/9999
    A100    A100,M100,M107,M102,M103,M104    1/1/2010    12/31/9999
    A101    A101,M105,M106                   1/1/2010    12/31/9999
    Results Required
    
    A100    A100,M100,M101,M102,M103,M104    1/1/2010    5/18/2013
    A100    A100,M100,M107,M102,M103,M104    5/20/2013   12/31/9999
    A101    A101,M105,M106                   1/1/2010    12/31/9999

    WITH the CLAUSE will make it readable

    SQL> with paths as
      2  (
      3        SELECT   CONNECT_BY_ROOT (b.sid) agent_sid,
      4                 TRIM (
      5                    LEADING ',' FROM    SYS_CONNECT_BY_PATH (b.sid, ',')
      6                                     || ','
      7                                     || b.emp_mgrs_id
      8                 )
      9                  PATH,
     10                 START_EFFECTIVE_DT Start_dt,
     11                 END_EFFECTIVE_DT End_dt,rownum rn
     12        FROM   PERSON_DTL b
     13        START WITH   sid IN ('A101', 'A100')
     14        CONNECT BY   PRIOR b.emp_mgrs_id = b.sid
     15  ),
     16  flagged as
     17  (
     18      select agent_sid,
     19             path,
     20             start_dt,
     21             end_dt,rn,
     22             case when path like lag(path) over(order by rn)||'%' then 0 else 1 end flg
     23      from paths
     24  ),
     25  summed as
     26  (
     27      select agent_sid,path,start_dt,end_dt,
     28             sum(flg) over(order by rn) sm
     29      from flagged
     30  )
     31  select agent_sid,max(path) path,max(start_dt) start_dt,
     32         min(end_dt) end_dt
     33  from summed
     34  group by agent_sid,sm
     35  order by agent_sid;
    
    AGENT_SID  PATH                                     START_DT  END_DT
    ---------- ---------------------------------------- --------- ---------
    A100       A100,M100,M101,M102,M103,M104            01-JAN-10 18-MAY-13
    A100       A100,M100,M107,M102,M103,M104            20-MAY-13 31-DEC-99
    A101       A101,M105,M106                           01-JAN-10 31-DEC-99
    
  • Include the expected start Date and end Date for the management of SSHRC-Absence

    Is it possible to include the scheduled Start Date and end Date of project to SSHRC, management of absences with the type of leave is confirmed?

    Thanks in advance

    Hello

    In this case, you should disable the option the absence request, so that by default all sheets are confirmed and the user do not have to apply once leave as planned and then comply.

    You can see the id metalink - "How do I disable the State of Absence of R12 Absence Management Page [ID 786691.1]" to understand how to disable "Planned" option to request authorization for simple customization.

    It will be useful.

    Thank you
    Sanjay

  • Search based on the start date and end date

    Hello

    I added two fields "Start Date" and "End Date" on a search page.
    I did the VO extension also.
    Now, I have to implement the logic of the search to get all records created between' start' and 'End Date' after pressing the "GO" button on this page.

    Can someone please provide advice to extend the controller.

    Thanks in advance.


    Gaurav.

    I think that the path would be

    Import oracle.apps.per.common.webui.PerTransactionTopCOImpl;

    Thank you
    -Anil
    http://oracleanil.blogspot.com/

  • Start and end Date Validation

    OK I'm lost and sought and made changes to what I do, but not sure I correct datasets or written something wrong.

    I have two date fields in my form. A Start Date and an end Date

    I put a validation that indicates the Start Date/time cannot be greater than the end Date/time or so I think that's what he said. But if I put and a date in the form of an hour after the beginning of end date, it throws the error

    Here are my details and maybe I'm just storing data wrong or something


    Validation ENDDATE: PL/SQL error:
    If to_date(:P6_DTGSTART) > to_date(:P6_DTGEND)
    raise_application_error (-20001, 'End Date must be greater than the Start Date.');
    end if;

    When I look at the data stored in the database SQL Workshop, this is what I see
    DTGSTART 11-29-2010
    DTGEND


    The entry in the form is a DatePicker to the format: DD-MON-YYYY HH24
    If the entry as well as:

    Start date/time November 29, 2010 09:25
    End date/time November 29, 2010 10:25

    The end date may be on the same date, but time must be greater than the start date/time

    Thank you
    Wally

    Check it out now...

    Thank you
    Machaan

  • Continuous start date and end date

    Hello

    I'm currently building a SQL query to get the min (start date) and max (end date) of the below dataset. The trick here is to consider the date min and max, if it is continuous otherwise are indicated separately. 1 January 01 is also the date of default null value in the system which is equivalent to 31-dec-2999.

    Set of input data

    MPRid METid START_DATE end_date
    ---------------------- ---------------------- ------------------------- -------------------------
    13940003 128127878 18 March 2008 March 19, 2008
    13940003 128127878 19 March 2008 March 27, 2008
    13940003 128127878 27 March 2008 1 January 01
    13940003 50368431 October 1, 1995 December 29, 1995
    13940003 50368431 29 December 1995 March 21, 1996
    13940003 50368431 March 21, 1996 February 22, 1997
    13940003 50368431 22 February 1997 December 18, 2001
    13940003 50368431 18 December 2001 March 11, 2008
    13940003 50368431 14 March 2008 March 15, 2008


    Expected results

    MPRid METid START_DATE end_date
    ---------------------- ---------------------- ------------------------- -------------------------
    13940003 128127878 18 March 2008 1 January 01
    13940003 50368431 1 October 1995 March 11, 2008
    13940003 50368431 14 March 2008 March 15, 2008

    I tried with partition but not getting is not the expected results. Looks like something wrong in the query. All suggestions will be of great help to me.

    Select mprid, metid
    min (start_date) start_date
    max (end_date) end_date
    from (select mprid, metid
    start_date
    decode(end_date,'01-Jan-0001','31-Dec-2999',end_date) end_date
    max (grp) on maxgrp (partition mprid, metid start_date order)
    from (select mprid, metid
    start_date
    End_date
    case lag (end_date) over (partition mprid, metid start_date order)
    When start_date then null
    rownum else
    end grp
    of table_mpc
    where mprid in (13940003) and metid is not null
    )
    )
    Mprid group, metid
    maxgrp
    order of mprid, start_date

    Thanks for looking in this query.

    Concerning
    Deborah

    Here's one way:

    with my_tab as (select 13940003 mprid, 128127878 metid, to_date('18-Mar-2008', 'dd-Mon-yyyy') start_date, to_date('19-Mar-2008', 'dd-Mon-yyyy') end_date from dual union all
                    select 13940003 mprid, 128127878 metid, to_date('19-Mar-2008', 'dd-Mon-yyyy') start_date, to_date('27-Mar-2008 ', 'dd-Mon-yyyy') end_date from dual union all
                    select 13940003 mprid, 128127878 metid, to_date('27-Mar-2008', 'dd-Mon-yyyy') start_date, to_date('01-Jan-0001 ', 'dd-Mon-yyyy') end_date from dual union all
                    select 13940003 mprid, 50368431 metid, to_date('01-Oct-1995', 'dd-Mon-yyyy') start_date, to_date('29-Dec-1995 ', 'dd-Mon-yyyy') end_date from dual union all
                    select 13940003 mprid, 50368431 metid, to_date('29-Dec-1995', 'dd-Mon-yyyy') start_date, to_date('21-Mar-1996 ', 'dd-Mon-yyyy') end_date from dual union all
                    select 13940003 mprid, 50368431 metid, to_date('21-Mar-1996', 'dd-Mon-yyyy') start_date, to_date('22-Feb-1997 ', 'dd-Mon-yyyy') end_date from dual union all
                    select 13940003 mprid, 50368431 metid, to_date('22-Feb-1997', 'dd-Mon-yyyy') start_date, to_date('18-Dec-2001 ', 'dd-Mon-yyyy') end_date from dual union all
                    select 13940003 mprid, 50368431 metid, to_date('18-Dec-2001', 'dd-Mon-yyyy') start_date, to_date('11-Mar-2008 ', 'dd-Mon-yyyy') end_date from dual union all
                    select 13940003 mprid, 50368431 metid, to_date('14-Mar-2008', 'dd-Mon-yyyy') start_date, to_date('15-Mar-2008 ', 'dd-Mon-yyyy') end_date from dual),
        -- end of mimicking your data into a table called "my_tab"
        results as (select mprid,
                           metid,
                           start_date,
                           decode(end_date, to_date('01/01/0001', 'dd/mm/yyyy'), to_date('31/12/2999', 'dd/mm/yyyy'), end_date) end_date,
                           case when start_date != lag(end_date) over (partition by mprid, metid order by start_date, end_date)
                                     or row_number() over (partition by mprid, metid order by start_date, end_date) = 1
                                     then row_number() over (partition by mprid, metid order by start_date, end_date)
                           end grp
                    from   my_tab),
      final_res as (select mprid,
                           metid,
                           start_date,
                           end_date,
                           last_value(grp ignore nulls) over (partition by mprid, metid order by start_date, end_date) grp
                    from   results)
    select mprid,
           metid,
           min(start_date) start_date,
           decode(max(end_date), to_date('31/12/2999', 'dd/mm/yyyy'), to_date('01/01/0001', 'dd/mm/yyyy'), max(end_date)) end_date
    from   final_res
    group by mprid, metid, grp
    order by mprid, metid, start_date;
    
         MPRID      METID START_DATE END_DATE
    ---------- ---------- ---------- ----------
      13940003   50368431 01/10/1995 11/03/2008
      13940003   50368431 14/03/2008 15/03/2008
      13940003  128127878 18/03/2008 01/01/0001
    

    Published by: Boneist on December 11, 2009 11:44
    (corrected for 1 St-Jan-0001 I missed!)

  • Use the project start Date and duration to calculate the end Date of project

    I'm trying to calculate the end date of the project in a report using the project end Date and time entered on the opportunity.
    For example, if the start date of the project filled an opportunity is 31/01/2009 and the length (integer) is entered on the opportunity is 5, the project end date is in the report must be 30/06/2009.

    I'm trying to TIMESTAMPADD forumaul allows you to add the duration (number of months) to the project start date
    This Fx works TIMESTAMPADD (SQL_TSI_MONTH, 12, '-used Custom Attributes ".) DATE_40)
    But if I try to replace the number twelve by the length (integer field) I get an error when you try to save: TIMESTAMPADD (SQL_TSI_MONTH, "-opportunity Custom Metrics".) S_INT_0, '-used custom attributes. DATE_40)

    Any ideas on how I can get this to work would be greatly appreciated.

    Hi, try this. It might solve your prioblem TIMESTAMPADD (SQL_TSI_MONTH, CAST (YOUR FIELD AS INTEGER), account. (' "Last modified")

    -John CRMIT

Maybe you are looking for