Summarise the results based on start and end dates

Hi All,
Can some body tells how to summarise a table results like in the below example?
I need help to get results as poc_dates_result from poc_dates table.
The data is supplied below to create the above tables.
Please provide the queries to convert poc_dates to poc_dates_result?
DROP TABLE poc_dates;
create table poc_dates
pid number
,start_dte date
,end_dte date
,prod char(3)
insert into poc_dates values(1,'01-JAN-2000','01-FEB-2000','PD1');
insert into poc_dates values(1,'02-FEB-2000','01-MAR-2000','PD1');
insert into poc_dates values(1,'02-MAR-2000','01-APR-2000','PD1');
insert into poc_dates values(1,'02-APR-2000','15-APR-2000','PD2');
insert into poc_dates values(1,'16-APR-2000','24-APR-2000','PD2');
insert into poc_dates values(1,'25-APR-2000','01-MAY-2000','PD3');
insert into poc_dates values(1,'02-MAY-2000','16-MAY-2000','PD3');
insert into poc_dates values(1,'17-MAY-2000','18-MAY-2000','PD1');
insert into poc_dates values(1,'19-MAY-2000','25-MAY-2000','PD1');
insert into poc_dates values(2,'01-JAN-2000','01-FEB-2000','PD1');
insert into poc_dates values(2,'02-FEB-2000','01-MAR-2000','PD1');
insert into poc_dates values(2,'02-MAR-2000','01-APR-2000','PD2');
insert into poc_dates values(2,'02-APR-2000','15-APR-2000','PD1');
insert into poc_dates values(2,'16-APR-2000','25-APR-2000','PD3');
insert into poc_dates values(3,'01-JAN-2000','01-FEB-2000','PD1');
insert into poc_dates values(3,'02-FEB-2000','01-MAR-2000','PD1');
insert into poc_dates values(3,'02-MAR-2000','01-APR-2000','PD2');
insert into poc_dates values(4,'01-JAN-2000','01-FEB-2000','PD1');
insert into poc_dates values(4,'02-FEB-2000','01-MAR-2000','PD2');
insert into poc_dates values(5,'01-JAN-2000','01-FEB-2000','PD1');
commit;
drop table poc_dates_result;
create table poc_dates_result
pid number
,start_dte date
,end_dte date
,prod char(3)
insert into poc_dates_result values(1,'01-JAN-2000','01-APR-2000','PD1');
insert into poc_dates_result values(1,'02-APR-2000','24-APR-2000','PD2');
insert into poc_dates_result values(1,'25-APR-2000','16-MAY-2000','PD3');
insert into poc_dates_result values(1,'17-MAY-2000','25-MAY-2000','PD1');
insert into poc_dates_result values(2,'01-JAN-2000','01-MAR-2000','PD1');
insert into poc_dates_result values(2,'02-MAR-2000','01-APR-2000','PD2');
insert into poc_dates_result values(2,'02-APR-2000','15-APR-2000','PD1');
insert into poc_dates_result values(2,'16-APR-2000','25-APR-2000','PD3');
insert into poc_dates_result values(3,'01-JAN-2000','01-MAR-2000','PD1');
insert into poc_dates_result values(3,'02-MAR-2000','01-APR-2000','PD2');
insert into poc_dates_result values(4,'01-JAN-2000','01-FEB-2000','PD1');
insert into poc_dates_result values(4,'02-FEB-2000','01-MAR-2000','PD2');
insert into poc_dates_result values(5,'01-JAN-2000','01-FEB-2000','PD1');
commit;
select * from poc_dates;
PID     START_DTE END_DTE     PROD
1     1/01/2000     1/02/2000     PD1
1     2/02/2000     1/03/2000     PD1
1     2/03/2000     1/04/2000     PD1
1     2/04/2000     15/04/2000     PD2
1     16/04/2000 24/04/2000     PD2
1     25/04/2000 1/05/2000     PD3
1     2/05/2000     16/05/2000     PD3
1     17/05/2000 18/05/2000     PD1
1     19/05/2000 25/05/2000     PD1
2     1/01/2000     1/02/2000     PD1
2     2/02/2000     1/03/2000     PD1
2     2/03/2000     1/04/2000     PD2
2     2/04/2000     15/04/2000     PD1
2     16/04/2000 25/04/2000     PD3
3     1/01/2000     1/02/2000     PD1
3     2/02/2000     1/03/2000     PD1
3     2/03/2000     1/04/2000     PD2
4     1/01/2000     1/02/2000     PD1
4     2/02/2000     1/03/2000     PD2
5     1/01/2000 1/02/2000     PD1
select * from poc_dates_result;
PID     START_DTE END_DTE PROD
1     1/01/2000     1/04/2000     PD1
1     2/04/2000     24/04/2000     PD2
1     25/04/2000 16/05/2000     PD3
1     17/05/2000 25/05/2000     PD1
2     1/01/2000     1/03/2000     PD1
2     2/03/2000     1/04/2000     PD2
2     2/04/2000     15/04/2000     PD1
2     16/04/2000 25/04/2000     PD3
3     1/01/2000     1/03/2000     PD1
3     2/03/2000     1/04/2000     PD2
4     1/01/2000     1/02/2000     PD1
4     2/02/2000     1/03/2000     PD2
5     1/01/2000     1/02/2000     PD1
Thanks,
CD
Edited by: cdprasad on Jul 15, 2010 10:52 AM

I'm sure there is simplest way to achieve this, but here below a try :
SQL> select pid,min(start_dte),max(end_dte),prod
  2  from   (select pid,start_dte,end_dte,prod,sum(flg) over (order by pid,prod,start_dte) sm
  3          from   (select pid,start_dte,end_dte,prod,
  4                         decode(start_dte-1,lag(end_dte) over (partition by pid,prod order by start_dte),0,1) flg
  5                  from   poc_dates))
  6  group by pid,prod,sm
  7* order by 1,4,2
SQL> /
       PID MIN(START_DTE)  MAX(END_DTE)    PRO
         1 01-JAN-00       01-APR-00       PD1
         1 17-MAY-00       25-MAY-00       PD1
         1 02-APR-00       24-APR-00       PD2
         1 25-APR-00       16-MAY-00       PD3
         2 01-JAN-00       01-MAR-00       PD1
         2 02-APR-00       15-APR-00       PD1
         2 02-MAR-00       01-APR-00       PD2
         2 16-APR-00       25-APR-00       PD3
         3 01-JAN-00       01-MAR-00       PD1
         3 02-MAR-00       01-APR-00       PD2
         4 01-JAN-00       01-FEB-00       PD1
         4 02-FEB-00       01-MAR-00       PD2
         5 01-JAN-00       01-FEB-00       PD1
13 rows selected.Nicolas.

Similar Messages

  • Hyperion Planning dynamic forms based on start and end date across years

    Hi All,
    I have a requirement where i need to be able to view a form showing periods across years that are dynamically built depending on the start and end dates. If i have a start date of 01/11/2009 and an end date of 31/7/2013 i want to be able to view a form that shows all of the periods (Jan,Feb etc) in a form that is driven by these dates, in addition it will need to show the actual scenario up to the current month and the forecast from the current month to the end date. So basically if a user inputs the start and end dates the form will display the relevant periods driven by these dates.
    Any tips very much appreciated!

    Hello,
    This is difficult to realize, but you can get quite far with a workaround. The first question is, where do you want to input your selection of time periods? Assuming you have a webform with the complete timeline in months and years and you type in the start period and end period.
    Webforms have the option to suppress rows and columns.
    This can be extended with option of empty cells or not empty cells.
    You will need to apply your creativity on this.
    Put every month-year combination in a column and add the suppression.
    Calculate the timeline between start period and end period with a dummy member, so data exists for these and columns will show.
    Maybe you will need to copy the required timeline into a separate version for this, to avoid having periods which were outside the selection and still have data.
    I hope these hints help a bit in this challenge.
    Regards,
    Philip Hulsebosch
    www.trexco.nl

  • Prorating Wage Type in IT0014 based on start and end dates

    Hi experts
    I have a scenario wherein I want to prorate a Wage type according to the start and end dates in Infotype 0014. I have tried setting the Processing Class 10 to 1. When I do this, the system prorates according to the start date. Example:
    If the start and the end dates for wagetype 4000 are: 24.05.2014 to 31.12.9999, amount is 1000 and the payroll period is May'2014, then amount calculated is 258.06, which is correct.
    If however, the start and the end dates for wagetype 4000 are: 01.05.2014 to 24.05.2014, amount is 1000 and the payroll period is May'2014, the system generates the amount 1000, which is incorrect.
    How can we handle this? Please help.
    Regards
    Divya Tiwari

    Hi Divya,
    Please check the below mentioned pcr's in your system.
    UW14 and X011
    Check above mentioned pcrs in subschemas INBD,ZNAP and share me the existing pcr's screenshot in your system.
    Regards,
    Haranath

  • Contract Start and End Dates in Sales Order

    Hi
    I have a situation where a service item is bundled with a deliverable item. The order is as follows
    Line Item    Mat                                                                 Qty            Higher Level Item               
    10              Item No.1 (Physical Item)                                  1             
    20              Item No.2 (Service Item)                                    1               10
    For the deliverable item 10 , Revenue is recognized immediately. For the Service item no.20 , revenue needs to be recognized over a period of 1 Year (It is a 1 year service contract).
    The whole order is created via BAPI from an external 3rd party order capture system.
    In order to do revenue recognition properly for service items , SAP I believe has 2 options
    1. Based on Billing plan dates
    2. Based on contract start dates
    Since order with both the line items need to produce 1 invoice, I cannot use billing plan . The only other option is to use contract start and end dates. I have enabled contract data at the sales order level. So when I enter the contract start and end dates manually at the line item level and set the item category to recognize revenue based on contract start and end dates based on time-based revenue recognition it is working fine.
    But I need a way to automate the population of contract start and end dates at the line item level. My ABAP guy is not able to find a user exit that can change the XVEDA or any VEDA structure in any of the user exits.
    I guess the SAP SD gurus out there would have definitely dealt with a situation of product bundling (Service and non-service items in the same sales order with one billing document , but seperate revenue recognition for service and non-service items)
    Please help.
    Thnx
    Siva

    Hi Siva,
    Kindly let me know what criteria you want to give for automatic population of start date of contract...
    Standard SAP comes with a few baseline dates for contract start date and we can control this from customization itself. 
    01     Today's date
    02     Contract start date
    04     Acceptance date
    05     Installation date
    06     Date contract signed
    07     Billing date/Invoice date
    08     CntrctStDate+contract duration
    09     Contract end date
    If you have some criteria which is not covered here, then let me know and i will try to provide some help then.
    Thanks
    Kapil Sharma

  • Effective start and end dates for a compensation workbench plan

    Hi all,
    We are having a requirement where we want to get the data respective to current plan for reporting purposes. What i have noticed is there is no such thing as effective_start_date and effective_end_date directly in all the cwb tables.
    The different dates we are looking at to capture the data are
    enrt_perd_start_dt and enrt_perd_end_dt
    upd_strt_dt and upd_end_dt
    within_yr_strt_dt and within_yr_end_dt
    But we have same plan with different enrollment period and start dates. We are planning to use max(data_freeze_date or lf_evt_occrd_dt) to get
    the records.
    select max(nvl(bcpdx.data_freeze_date, bcpdx.lf_evt_ocrd_dt))
    from ben_cwb_pl_dsgn bcpdx
    where bcpdx.pl_id = p_pl_id)
    Catch with this is, We have 62 business groups off which only 50 might run the plan next year and ohters might not. in that case it will also return data for all the BG's including the 12 BG's where plan has not been run for that year.
    Any suggestions or help will greatly be appreciated.
    Thanks
    Hari

    Hi Ankush,
    I am also of the same opinion. Start and end dates can probably be enforced by a policy condition in AM but would lead to proliferation of policies as we would end up creating policies per role entitlement duration for a user.
    Any thoughts on whether the sunrise/sunset concept of Identity Manager can be used for this requirement.
    Thanks,
    Srinivas

  • Effective start and end dates for roles/group assignment

    Hi,
    Does Access Manager (in legacy or realm) mode support effective start date/end date on a role/group assignment on a user?
    Thanks,
    Srinivas

    Hi Ankush,
    I am also of the same opinion. Start and end dates can probably be enforced by a policy condition in AM but would lead to proliferation of policies as we would end up creating policies per role entitlement duration for a user.
    Any thoughts on whether the sunrise/sunset concept of Identity Manager can be used for this requirement.
    Thanks,
    Srinivas

  • Calculate the working days having the start and end dates only

    Hi,
    Can BIP be able to calculate the working days having the start and end dates only? It is like the NETWORKDAYS function in Excel. (i.e. excluding weekends and holidays).
    Thanks.

    Not out of the box.
    But You could extend your BIP functions
    Look at here:
    http://blogs.oracle.com/xmlpublisher/2009/05/bip_by_extension.html
    Based on that what you need is similar to the following Java code:
    http://objectlabkit.sourceforge.net/
    regards
    Jorge A.

  • Getting the start  and end dates of the week

    Hi,
    I was stuck with a problem in getting the start date and end date of the week,i know the month ,week and year also,with these three values how can i get the start and end dates of a week.please help me
    Thanks

    There is no simple way. It has to be a math calculation.
    There are several ways you can get the dates. First you have to know what day is January 1st and what day is december 31st for a particular year. Second you have to check whether the given year is a leap year or not. Based on the abvove information you should be able to find out what day is a particular date.
    Hope this helps to get you started.
    - Venkat Dhurjati.

  • Define the start and end dates of an assigned academic period in fee calc.

    Define the start and end dates of an assigned academic period
    Message no. HRPIQ00ACCOUNTING132
    Diagnosis
    The academic calendar assigned to the top organizational unit does not contain a start or end date for the academic period (academic year and session) assigned to fee calculation period Z000.
    System Response
    The system will skip fee calculation period Z000 and continue processing with the next fee calculation period.
    Procedure
    1. Check which academic calendar is assigned to the top organizational unit.
    2. Check which academic period is assigned to fee calculation period Z000. You check this setting in Customizing for Campus Management in the IMG activity Assign Academic Years and Sessions to Fee Calculation Periods.
    3. In this academic calendar, create the start and end dates of the relevant academic period using standard time limit 0100 (standard duration of academic period) or a corresponding user-defined time limit.
    For more information, see
    Define Top Organizational Unit
    Define Mandatory Time Limits for Academic Calendar
    please give me the needful information to solve this problem.
    Regards
    Arun Rai

    Arun,
    Have you looked in the Student Accounting Cookbook  
    http://www.sdn.sap.com/irj/scn/advancedsearch?query=studentaccountingcookbook   on page 13? 
    Page 1-18 will help you setup the Oranizational unit, the academic calendar and the modules.
    Bev beck

  • Adding a summary column in a table which contains the start and end dates in the week

    Hi,
    I've got a DIMENSION DATE table and want to add in another column which shows the start and end date of the week.
    See below, the new column is WEEKOFYEARTEXT.
    Does anybody know how i may generate this column using SQL and using the existing columns?
    Umar Javed

    See:  http://www.sqlusa.com/bestpractices/datetimeconversion/
    DECLARE @Year INT = '2015';
    WITH cteDays AS (SELECT DayOfYear=Dateadd(dd, number,
    CONVERT(DATE, CONVERT(char(4),@Year)+'0101'))
    FROM master.dbo.spt_values WHERE type='P'),
    CTE AS (SELECT DayOfYear, WeekOfYear=DATEPART(week,DayOfYear)
    FROM cteDays WHERE YEAR(DayOfYear)= @YEAR)
    SELECT WeekOfYear, StartOfWeek=MIN(DayOfYear), EndOfWeek=MAX(DayOfYear)
    FROM CTE GROUP BY WeekOfYear ORDER BY WeekOfYear;
    WeekOfYear StartOfWeek EndOfWeek
    1 2015-01-01 2015-01-03
    2 2015-01-04 2015-01-10
    3 2015-01-11 2015-01-17
    4 2015-01-18 2015-01-24
    5 2015-01-25 2015-01-31
    6 2015-02-01 2015-02-07
    7 2015-02-08 2015-02-14
    8 2015-02-15 2015-02-21
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Database Design
    New Book / Kindle: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2014

  • How to find the start and ending dates of a quarter of a particular fiscal

    Hi Experts,
    I need a function mudule which returns starting and ending date s of a particular quarter of a particular fiscal year .
    For Example: if pass 1 quarter and 2002 or 2 quarter 2002 it has to give me the star and end dates of that particular quarter na d fiscal year.
    Please help me which is urgent for me.

    Hi Kishan thanks for reply.
    But given function module the 2nd one is full but it is giving me the calender year dates but i need fiscal yea dates.
    fro example: if i pass 1 st quarte and 2006 it is to give me the 1st-april to 30-jun2006.
    And need this quater starting date and ending date for as per USA fiscal year calender.
    If u get any idea plz let me know.
    thanks.
    Dashmantha.

  • FM to find week start and end date on the basis of a given date

    Hi Everyone,
    I have a requirement in which I require the week start and end date  of any given date.
    For eg: The given date is Wednesday 24.03.2010, I need a function module to calculate the week start date ie. Monday 22.03.2010 and week end date ie. Sunday 28.03.2010 on the basis of that date.
    Any input to this query would be helpful.
    Thanks,
    Nimisha Agarwal
    Edited by: Nimisha Agarwal on Jul 7, 2010 7:47 AM

    HI nimisha,
    many posts r there for this .
    Kindly check  before posting
    anyways this FM will serve u  r purpose.
    GET_WEEK_INFO_BASED_ON_DATE

  • Start and End Dates check

    Hi,
    I have a requirement to find the list of persons who have overlapping dates.
    Each person can have many start and End Dates, but only one row that has a NULL end date, the active record. If the start and end dates are overlapped, like in the example below, the second row should have a start date of 24-DEC-2006 and not 22-DEC-2006. Is it possible to list those persons who have overlapping dates/gap in the dates.
    Empl_ID Start Date End Date
    12345 01-JAN-2006 23-DEC-2006
    12345 22-DEC-2006 13-JAN-2007
    12345 14-JAN-2007 NULL
    Any help is greatly appreciated.
    Thanks!

    Hi Patrick
    I like where you are coming from. I hope you don't mind but I have extended your idea slightly to add in a PARTITION BY clause to make sure we look at records for the same person. Also, if we LAG to get a previous record shouldn't we LAG the END_DATE and compare it with the current START_DATE?
    LAG(END_DATE,1) OVER (PARTITION BY EMPL_ID ORDER BY START_DATE)
    Doing this, then the results would look like this:
    Empl_ID Start Date End Date Lag Date
    12345 01-JAN-2006 23-DEC-2006 NULL
    12345 22-DEC-2006 13-JAN-2007 23-DEC-2006
    12345 14-JAN-2007 NULL 13-JAN-2007
    This would give the SIGN an issue because in the first record the LAG would be NULL and in the last record the END_DATE would be NULL. So it looks like some manipulation of NULLs has to take place as well which I will deal with later.
    SIGN((LAG(END_DATE,1) OVER (PARTITION BY EMPL_ID ORDER BY START_DATE)) - START_DATE)
    Anytime the difference between the Lag Date and the Start Date is positive this means this is an overlap which means we do need to look for any variance where the SIGN is 1.
    Using the other function, we could use LEAD like this:
    LEAD(START_DATE,1) OVER (PARTITION BY EMPL_ID ORDER BY START_DATE)
    Doing this, then the results would look like this:
    Empl_ID Start Date End Date Lead Date
    12345 01-JAN-2006 23-DEC-2006 22-DEC-2006
    12345 22-DEC-2006 13-JAN-2007 14-JAN-2007
    12345 14-JAN-2007 NULL NULL
    which when combined with SIGN becomes: SIGN((LEAD(START_DATE,1) OVER (PARTITION BY EMPL_ID ORDER BY START_DATE)) - END_DATE)
    This time you would be looking for the SIGN to be -1
    Personally, I think I would prefer the LEAD function because a) there would always be a START_DATE, and b) we could replace all of the possible NULLs with the SYSDATE to get a final calculation like this:
    SIGN(NVL(LEAD(START_DATE,1) OVER (PARTITION BY EMPL_ID ORDER BY START_DATE),TRUNC(SYSDATE)) - NVL(END_DATE, TRUNC(SYSDATE)))
    Based on the current date being 17-NOV-2009, you would now get this result:
    Empl_ID Start Date End Date Lead Date
    12345 01-JAN-2006 23-DEC-2006 22-DEC-2006
    12345 22-DEC-2006 13-JAN-2007 14-JAN-2007
    12345 14-JAN-2007 17-NOV-2009 17-NOV-2009
    Best wishes
    Michael

  • SNP Planned order start and end dates are not calculated correctly

    Hello SNP Guru's
    The SNP planned orders generated after the Heuristics run, have a start and end date based on the Activity Duration (Fixed), while the resource consumption is based on the Bucket Consumption (Variable), which is correct.
    The Activity Duration (Fixed) is based on the BOM Base Quantity. So if the Activity Duration = 1 day, and if the order quantity is more than a day, the start and end dates, still shows as 1 day. So no matter what is the order quantity, the start and end dates is always = 1 day.
    Does anyone have any experience in implementing any code to change the start and end dates on SNP Planned Order?
    Seems like it should work as standard.
    Am i missing something?
    Thanks,
    Mangesh

    Dear Mangesh,
    SNP is a infinite planning tool. If you have defined fixed duration to be 1 DAY in the activity, no matter how many quantity you input for your planned order, the order will last for one day. If the resourced is overloaded, you then run capacity levelling to
    banlance the capacity. What your expected beahavior happens in PPDS planning.
    Claire

  • Calculate Start and End date in Connect By -- When Hirerchy Changes

    /* Formatted on 5/20/2013 9:53:00 AM (QP5 v5.115.810.9015) */
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    Hello , Can some one Please help me or Guide me in calculating Start and End dates for the below logic
    I want to calculate the Manager Hirerchy for the given Agent.
    Then Below Query is working fine and its giving me the desired results
    But when there is a change in the Manager Hirerchy 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

    May be this..
    SQL> select agent_sid,max(path) path,max(start_dt) start_dt,
      2         min(end_dt) end_dt
      3  from
      4  (
      5    select agent_sid,path,start_dt,end_dt,
      6           sum(flg) over(order by rn) sm
      7    from
      8    (
      9      select agent_sid,
    10             path,
    11             start_dt,
    12             end_dt,rn,
    13             case when path like lag(path) over(order by rn)||'%' then 0 else 1 end flg
    14      from
    15      (
    16        SELECT   CONNECT_BY_ROOT (b.sid) agent_sid,
    17                 TRIM (
    18                    LEADING ',' FROM    SYS_CONNECT_BY_PATH (b.sid, ',')
    19                                     || ','
    20                                     || b.emp_mgrs_id
    21                 )
    22                  PATH,
    23                 START_EFFECTIVE_DT Start_dt,
    24                 END_EFFECTIVE_DT End_dt,rownum rn
    25        FROM   PERSON_DTL b
    26        START WITH   sid IN ('A101', 'A100')
    27        CONNECT BY   PRIOR b.emp_mgrs_id = b.sid
    28      )
    29    )
    30  )
    31  group by agent_sid,sm
    32  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-99Edited by: jeneesh on May 20, 2013 7:54 PM
    Not thoroughly tested.And not sure whether an easy way exists..

Maybe you are looking for

  • How can I download a external hard drive to my MacBook pro ?

    they have to replace my Macbook Disc , and before the exchange of the disk I back up my pictures, videos, music,etc.. to a external hard dirve disk. now I have my macbook with me with the new disk , please somebody tell me how to pass the external ha

  • MP3 Music does not work.

    I just upgraded to Adobe Premiere Elements 13 so that I could use music in .MP3 format.  But it still doesn't let me use this music.  Can you tell what I am doing wrong? I get a message that says "The importer reported a generic error"

  • [AS3] how do i use this angle in another lower level movie clip?

    i'm tryin to use an angle from one movie clips to be part of an if statement in another lower level movie clip. my code is probably ugly but here it is. thank you in advance for the help

  • Help with 6500S and ringtones

    I have downloaded 2 ringtones to my phone but I can only set them as the main ringing tone, I was to set one of them to one of my groups but they don't appear in my ringtone selection when I go to change the group ring tone, can someone help they are

  • Hello, I'm having trouble with my ipod

    hello, I'm having trouble with my ipod