Split period into different date ranges

Hi,
Can someone let me know if there is any standard Function module that can split up the periods? For example I have a total period 01.01.2008 to 31.12.2008 and I have a split period of 01.04.2008 to 30.04.2008.
Now my resultant period should be,
1. 01.01.2008 to 31.03.2008
2. 01.04.2008 to 30.04.2008
3. 01.05.2008 to 31.12.2008
Thanks,
Prasath N

Are there no programmers around your site?  This really is tremendously basic.
PARAMETERS: p_dat TYPE d.
CONSTANTS: c_start_of_all_periods TYPE d VALUE '20080101',
           c_end_of_all_periods   TYPE d VALUE '20081231'.
DATA: start_of_first_period TYPE d,
      end_of_first_period   TYPE d,
      start_of_split_period TYPE d,
      end_of_split_period   TYPE d,
      start_of_2nd_period   TYPE d,
      end_of_2nd_period     TYPE d.
IF p_dat LT c_start_of_all_periods OR p_dat GT c_end_of_all_periods.
  WRITE: / 'Outside range'.
  EXIT.
ENDIF.
start_of_split_period = p_dat.
start_of_first_period = c_start_of_all_periods.
end_of_2nd_period = c_end_of_all_periods.
* Get first day of supplied month
start_of_split_period+6(2) = '01'.
* Get day before the first day of supplied month
end_of_first_period = start_of_split_period - 1.
start_of_2nd_period = start_of_split_period.
start_of_2nd_period+6(2) = '28'. " Get 28th of supplied month
ADD 4 TO start_of_2nd_period. " Get 4 days later - this will be in next month
start_of_2nd_period+6(2) = '01'. " Get first day of next month
end_of_split_period = start_of_2nd_period - 1. " Get day before start of 2nd period
WRITE: / start_of_first_period,
         end_of_first_period,
         start_of_split_period,
         end_of_split_period,
         start_of_2nd_period,
         end_of_2nd_period.
If you are a programmer, I hope this sample is sufficient to show how to deal with all kinds of date handling coding problems.
matt

Similar Messages

  • How to translate dashboard prompt year/period into literal date range

    I am using OBIEE 10g. I have a dashboard that prompts for a fiscal year and fiscal period (both are numeric data types). I need to use these values in the date filter for my answers request - however, to fully utilize the indexes and partitioning that have been set up on my fact table (Teradata database) I need to be able to convert fiscal year/period to a literal date range and pass literal date values (i.e. 10/01/2011 - 10/31/2011) to my answers filter. So far I have been unable to do this, I'm hoping someone has some ideas.
    Here are some things I've tried so far:
    In the dashboard prompt, set variables var_year and var_period (which would be set to 2012 and 10, respectively). Create a filter on my answers request for Date (from calendar dimension) that calculates a min/max date value based on var_year and var_period. While this works to return data, the sql is not optimized as it does not contain literal date values for the filter (10/01/2011 - 10/31/2011).
    Create a subreport that takes the year/period from the dashboard prompt and calculates 2 columns, one for the "From Date" (using min calculation) and one for the "To Date" (using max calculation). Then create a filter on my answers request that uses the results of this subreport to create the date filter. Again this works - however, instead of passing the literal date values for from and to dates, it passes the min/max calculations so that these are executed again in the answers request sql. Therefore again this is not optimized, as it is not passing literal date values for the filter.
    I have only been able to get this to work by creating a prompt for entering a from and to date directly, and using this to pass to the answers request filter. This generates optimized sql as it contains literal date values. However, this is not acceptable to the users as they want to enter fiscal year/fiscal period at the dashboard prompt, not a date range.
    I have tried to get the fiscal year/fiscal period columns in the dashboard prompt to set another dashboard prompt for a date range, thinking I could then set new presentation variables for those from/to columns to use in the answers request, but I can't figure out how to do this. Is this even possible, to use a dashboard prompt value to set a subsequent dashboard prompt value?
    Is there some other method of converting these prompt values to literal dates that I am missing?
    Thanks in advance for any help you can provide.
    Rhonda

    Disregard. I gave up and just brought in the Fiscal Period Start Date and Fiscal Period End Date to the rpd so I can use them in the dashboard prompt, created presentation variables for each, and used those in the report filter.

  • How To UPLOAD a DATA (.DAT) fiel from PC to internal table and then split it into the data different columns

    Hi all,
    I am new to ABAP Development. I need to upload a .DAT file (the file doesn#t have any proper structure-- Please find the .DAT file in the attachment). After uploading the DATA (.DAT) fiel I need to split in into different columns. Refering the attached .DAT fiel the fields in bracets like:
    [Arbeitstag],  [Pecunia], [Mita], [Kunde], [Auftrag] and  [Position] are different fields that need to be arranged in columns in an internal table. this .DAT fiel which I want to upload and then SPLIT it into various fields will will treated as MASTER DATA table for further programming. The program that I had written is as below. Also please refer the attached .DAT table.
    Please if any one could help me. i searched a lot in different forums but couldn't find me  a solution. Also note that the attached fiel is in text (.txt) format here but in real situation the same fiel is in DATA (.DAT) format.
    *& Report  ZDEMO_ZEITERFASSUNG9
    REPORT  ZDEMO_ZEITERFASSUNG9.
    Types: Begin of ttab,
            Rec(1000) type c,
           End of ttab.
    DATA: itab  type table of ttab.
    DATA: wa_tab type ttab.
    DATA: file_str type string.
    Parameters: p_file type localfile.
    At selection-screen on value-request for p_file.
                                           CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
                                            EXPORTING
    *                                          PROGRAM_NAME        = SYST-REPID
    *                                          DYNPRO_NUMBER       = SYST-DYNNR
    *                                          FIELD_NAME          = ' '
                                               STATIC              = 'X'
    *                                          MASK                = ' '
                                             CHANGING
                                               file_name           = p_file.
    *                                        EXCEPTIONS
    *                                          MASK_TOO_LONG       = 1
    *                                          OTHERS              = 2
    Start-of-Selection.
      file_str = P_file.
      CALL FUNCTION 'GUI_UPLOAD'
        EXPORTING
          filename                      = '\\10.10.1.92\Volume_1\_projekte\Zeiterfassung-SAP\BUP_ZEIT.DAT'   " This the file  source address
          FILETYPE                      = 'DAT'
          HAS_FIELD_SEPARATOR           = ';'
    *     HEADER_LENGTH                 = 0
    *     READ_BY_LINE                  = 'X'
    *     DAT_MODE                      = ' '
    *     CODEPAGE                      = ' '
    *     IGNORE_CERR                   = ABAP_TRUE
    *     REPLACEMENT                   = '#'
    *     CHECK_BOM                     = ' '
    *     VIRUS_SCAN_PROFILE            =
    *     NO_AUTH_CHECK                 = ' '
    *   IMPORTING
    *     FILELENGTH                    =
    *     HEADER                        =
        tables
          data_tab                      = itab
       EXCEPTIONS
         FILE_OPEN_ERROR               = 1
         FILE_READ_ERROR               = 2
         NO_BATCH                      = 3
         GUI_REFUSE_FILETRANSFER       = 4
         INVALID_TYPE                  = 5
         NO_AUTHORITY                  = 6
         UNKNOWN_ERROR                 = 7
         BAD_DATA_FORMAT               = 8
         HEADER_NOT_ALLOWED            = 9
         SEPARATOR_NOT_ALLOWED         = 10
         HEADER_TOO_LONG               = 11
         UNKNOWN_DP_ERROR              = 12
         ACCESS_DENIED                 = 13
         DP_OUT_OF_MEMORY              = 14
         DISK_FULL                     = 15
         DP_TIMEOUT                    = 16
         OTHERS                        = 17
      IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      LOOP at itab into wa_tab.
            WRITE: / wa_tab.
      ENDLOOP.
    I will be grateful to all you experts for ur inputs
    regards
    Chandan Singh

    For every Auftrag, there are multiple Position entries.
    Rest of the blocks don't seems to have any relation.
    So you can check this code to see how internal table lt_str is built whose first 3 fields have data contained in Auftrag, and next 3 fields have Position data. The structure is flat, assuming that every Position record is related to preceding Auftrag.
    Try out this snippet.
    DATA lt_data TYPE TABLE OF string.
    DATA lv_data TYPE string.
    CALL METHOD cl_gui_frontend_services=>gui_upload
      EXPORTING
        filename = 'C:\temp\test.txt'
      CHANGING
        data_tab = lt_data
      EXCEPTIONS
        OTHERS   = 19.
    CHECK sy-subrc EQ 0.
    TYPES:
    BEGIN OF ty_str,
      a1 TYPE string,
      a2 TYPE string,
      a3 TYPE string,
      p1 TYPE string,
      p2 TYPE string,
      p3 TYPE string,
    END OF ty_str.
    DATA: lt_str TYPE TABLE OF ty_str,
          ls_str TYPE ty_str,
          lv_block TYPE string,
          lv_flag TYPE boolean.
    LOOP AT lt_data INTO lv_data.
      CASE lv_data.
        WHEN '[Version]' OR '[StdSatz]' OR '[Arbeitstag]' OR '[Pecunia]'
             OR '[Mita]' OR '[Kunde]' OR '[Auftrag]' OR '[Position]'.
          lv_block = lv_data.
          lv_flag = abap_false.
        WHEN OTHERS.
          lv_flag = abap_true.
      ENDCASE.
      CHECK lv_flag EQ abap_true.
      CASE lv_block.
        WHEN '[Auftrag]'.
          SPLIT lv_data AT ';' INTO ls_str-a1 ls_str-a2 ls_str-a3.
        WHEN '[Position]'.
          SPLIT lv_data AT ';' INTO ls_str-p1 ls_str-p2 ls_str-p3.
          APPEND ls_str TO lt_str.
      ENDCASE.
    ENDLOOP.

  • Splitting TempDB into multiple data files.

    To avoid contention we have to split tempdb into multiple data files. But as for case suppose, there is 20 GB total space is on the drive containing 1 tempdb data file of 15 GB. And I have to create 3 more tempdb data files, and as recommendation all files
    should be of same size.Then how to handle this situation and configure all data files with same size?
    Pranshul Gupta

    But as for case suppose, there is 20 GB total space is on the drive containing 1 tempdb data file of 15 GB. And I have to create 3 more tempdb data files, and as recommendation all files should be of same size.Then how to handle this situation and configure
    all data files with same size?
    So your goal is to have 4 tempdb files, each 5GB?  Below is a sample script to accomplish the task within the 20GB space constraint.
    --reduce size of existing file to 5GB
    ALTER DATABASE tempdb
    MODIFY FILE (NAME='tempdev', Size=5GB);
    DBCC SHRINKFILE('tempdev',5120);
    --add 3 new 5GB files
    ALTER DATABASE tempdb
    ADD FILE (NAME='tempdev2', FILENAME='D:\SqlDataFiles\tempdb2.ndf', Size=5GB);
    ALTER DATABASE tempdb
    ADD FILE (NAME='tempdev3', FILENAME='D:\SqlDataFiles\tempdb3.ndf', Size=5GB);
    ALTER DATABASE tempdb
    ADD FILE (NAME='tempdev4', FILENAME='D:\SqlDataFiles\tempdb4.ndf', Size=5GB);
    Dan Guzman, SQL Server MVP, http://www.dbdelta.com

  • Crosstab or Crosstabs with different date ranges not lining up.

    I have a crosstab with a dimension (item) in the vertical axis, and different date ranges on the Horizontal (top) axis.
    I want to display counts of a measure over specific ranges of time. For instance, count of items sold for weeks 1,2,3,4, horizontally, then count of items sold for months 1,2,3,4 horizontally, next to each other.
    Problem is that count rows by item do not line up. Count by week has fewer items, so it has fewer rows than the counts by month. I need it to have the same number of rows, and just show 0 or blank in that row, instead of just not being there. I need all rows to line up by item.
    Its like there needs to be an outer join, but I haven't been able to make it work. What am I missing?
    Does that make sense?
    Any ideas welcome. Thank you!

    Wavery,
    You are looking to display a grid with a high degree of consistency, regardless of the data present.  There is no "single" step capability provided by WebI to achieve this, so it requires creativity on your part.  A second data provider (DP) for your report is necessary and can be either a view in your database, a custom SQL, or some folks have even built a derived table in their universe to accommodate.  At any rate, there are one of two ways to achieve.  If you are familar with SQL and the "union" statement, you would run the basic SQL, then via union, dummy up a second query that has all the requisite columns, but for the measures you would use a value of zero so as not to affect the generated facts.  For example, suppose you had a report for a hardware store, and you wanted to track the following items:  Nails, Flashlights, and Screws.  Your basic query might look like this:
    select item,sum(inventory) from inventory_table where item in ('nail','flashlight','screw') group by item
    Then your next portion of code:
    union select 'Nail',0 union select 'Flashlight',0 union select 'Screw',0
    See how the union is providing "dummy" info?  To do this in WebI with a second DP, you would not use union, but a separate view perhaps, then in WebI apply Merge Dimensions on the item column (and the equivalent of an outer join).
    Thanks,
    John

  • Can we send the data into different data target from single datasource how

    Hai
    can we send the data into different data target from single datasource how ?

    Hi,
    Create the transformation for each target and connect through DTP if you are in BI 7.0
    If it is BW 3.5 create transfer rules and load it Info source and then different update rules for different targets then load it using IP.
    If you are speaking about loading data from R3 data source to multiple data sources in BI
    Then follow the below step.
    1)create init IP's and run the IP's with different selection to different DSO(With same selection it is not possible).
    2)Then you will have different delta queues for the same data source in RSA7
    3)Your delta loads will run fine to different data sources from same DS in R3.
    Hope this helps
    Regards,
    Venkatesh

  • HT1349 why when i import a comperlation cd into my itunes library  it splits it into different parts

    hello when i import a cd in to my itunes  library from my collection  it spliys it into differant albums ect   acample my epic cd x3  is split into about 20 alboms

    You either put in a blank CD as roaminggnome suggests, or something mechanical went wrong with your player, damaging the CD.  Check for scratches.
    iTunes has no facility for erasing a CD.  You would have to deliberately do that with a disk or DC burning utility.

  • Display of 2 rows of data for 2 different date range selection

    Hi Folks,
    I have a requirement as follows,
    User has an option of selecting 2 Date Ranges
    From and To Date and again From and To Date
    The result should display 2 different rows of data with From and To Date range selection.
    Eg:
    12/09/20008 to 03/09/2009           10 20 30 40
    23/10/2009 to  18/12/2010           40 20 10 30
    Difference                                   30 0  20 10
    % Change                                   x  y  z   q
    Thanks for your input.
    Regards,
    KJ

    You will need to use union report, and you would have fours union's in this report.
    Union - 1: Data from 1st Date Range
    Union - 2: Data from 2nd Date Range
    Union - 3: Variance Calculation
    Union - 4: Percentage Variance Calculation.
    If the date's are coming from the same field, use cast function to use the same column twice in your prompts. Apply filters on each union as needed.
    Thanks.

  • How to use decode to calculate sum for different date range

    I'm stuck with decode() function:
    I have a table like this:
    (project_id, approve_date, value, builder_code)
    I want to write a SQL query to get sum of values for different month of the approve_date, and group by builder_code)
    The result is like this:
    builder_code Sum(value)_Sep-03 Sum(value)_Oct-03 Sum(value)_Nov03
    1001 1,299 1,322 990
    1002 3,332 1,222 333
    I tried to use decode for this question but could not get the answer.
    Thanks a lot

    I don't think you need a DECODE() here. I'd do something like this-
    create table builder (
        project_id number,
        approve_date date,
        value        number,
        builder_code number
    insert into builder values( 1, to_date('09-01-2003', 'MM-DD-YYYY'), 100, 990 )
    insert into builder values( 2, to_date('09-03-2003', 'MM-DD-YYYY'), 150, 990 )
    insert into builder values( 3, to_date('09-05-2003', 'MM-DD-YYYY'), 250, 990 )
    insert into builder values( 3, to_date('09-05-2003', 'MM-DD-YYYY'), 250, 333)
    SELECT sept.builder_code, sept.sept_sum, oct.oct_sum
    FROM (SELECT builder_code, sum(value) sept_sum
            FROM builder
           WHERE approve_date >= to_date('09-01-2003','MM-DD-YYYY')
             AND approve_date < to_date('10-01-2003','MM-DD-YYYY')
           GROUP BY builder_code) sept,
         (SELECT builder_code, sum(value) oct_sum
            FROM builder
           WHERE approve_date >= to_date('10-01-2003','MM-DD-YYYY')
             AND approve_date < to_date('11-01-2003','MM-DD-YYYY')
           GROUP BY builder_code) oct
    WHERE oct.builder_code(+) = sept.builder_code
    BUILDER_CODE   SEPT_SUM    OCT_SUM
             333        250
             990        500Justin
    Distributed Database Consulting, Inc.
    www.ddbcinc.com/askDDBC

  • Crosstab Columns Need to be two different date ranges

    I'm fairly new to CR and don't know crystal or basic syntax or any coding really.
    Using the crosstab expert, I need two columns that are based on a range of dates.  Unfortunately the range of dates are not any of the choices I have when I just bring the date into that column box in the expert.
    My two columns:
    Column 1 = 11/01/2007 12:00:00:00 AM to 10/31/2008 12:00:00:00 AM
    Column 2 = 11/01/2008 12:00:00:00 AM to 10/31/2009 12:00:00:00 AM
    When I insert a crosstab and use the expert I have two choices for the columns box.  I can either create two new formulas or use the group options.  I've tried my very inexperienced hand at creating some formulas with laughable results.  The group options, although lovely, don't meet my very specific date needs.
    Anyone out there have the time to help me?  It would be much appreciated.

    Hello Anne,
    Try creating a formula similar to the following;
    if in datetime(2007,11,1,12,00,00) to datetime(/2008,10,31,12,00,00)
    then "11-2007 to 10-2008"
    else if in datetime(2008,11,1,12,00,00) to datetime(/2009,10,31,12,00,00)
    then "11-2008 to 10-2009"
    and use this formula as the column field in the crosstab.

  • Split orders into different billing documents depending on exchange rate

    We are going to have a new business and process sales orders with currencies.
    As our materials have a long life cycle and for commercial reasons, users want to freeze the currency rate on the material.
    Our first analysis leads us to use the pricing date on item, to get it from the u201Csale from dateu201D maintened on the material, so SD determines the exchange rate valid at this date in the currency table (TCURR). This exchange rate is kept on the order item in the u201Cexchange rateu201D field (VBKD-KURSK).
    So we can have in the same order (and obviously for the same currency) items with diffrent exchange rates.
    Now, we would like to split the billing document depending on the exchange rate (or the pricing date is it determines the rate). My question is : how to do this ? Is there a way thru u201CCopying control: Sales document to billing documentu201D ?

    Thank you Caveman
    We have added a new routine to concatenate the exchange rate in the VBRK-ZUKRI field and it works !

  • Problems with splitting result into different rows. Group by-issue?

    Hi all!
    I have a table that looks a bit like this:
    Pallet          Status          Number          Time
    A          MoveIn          48          11:11
    A          Pick          -1          11:11
    A          Pick          -1          11:12
    A          Pick          -1          11:12
    A          MoveOut     45          11:13
    A          MoveIn          45          18:20
    A          Pick          -1          18:23
    A          Pick          -1          18:23
    A          Pick          -1          18:23
    A          Pick          -1          18:24
    A          MoveOut     41          18:25
    A          MoveIn          41          21:31
    A          Pick          -1          21:55
    .....This is logging pallets that is moved to one station and then number of boxes are picked off. (For making it more simple, I only show one pallet in above example.)
    I would like to present the result with one row for each time the pallet have been at the station, like:
    Pallet          Picked          Time
    A          3          11:11
    A          5          18:20
    A          ....          .....This means that the same pallet might be showned on several rows, as it has been to the station several times. I have tried several different "GROUP BY" but I cannot make it work.
    For example I have tried to group by hour, but this fails if a pallet is moved twice per hour or if boxes are picket at different hours (eg, first box picked 09:59, last box 10:01)
    Does anyone have a suggestion how to solve this?
    Thanks in advance and Kind regards / Anders from Sweden

    Hej, Anders,
    Can you explain what defines a group?
    It looks like you're saying that a group is a sub-set of a pallet. If we arrange all the rows for a pallet in order by time, then a new group will start every time we have a row where status='MoveIn'. That is, a group consists of a row with status='MoveIn', and all the rows immediately following it, in order by time, up to, but not including, the next row with status=-'MoveIn'. Is that right?
    If so, you can use the analytic COUNT (or SUM) function to find out how many rows with status='MoveIn' have already occurred, in order by time, like this:
    WITH     got_grp          AS
         SELECT     pallet, status, time
         ,     COUNT ( CASE
                             WHEN  status = 'MoveIn'
                       THEN  1
                         END
                    ) OVER ( PARTITION BY  pallet
                                ORDER BY          time
                        )           AS grp
         FROM    table_x
    SELECT       pallet
    ,       COUNT ( CASE
                      WHEN  status = 'Pick'
                    THEN  1
                  END
                )          AS picked
    ,       MIN (time)          AS start_time
    FROM       got_grp
    GROUP BY  pallet
    ,            grp
    ORDER BY  pallet
    ,            grp
    ;If you'd care to post CREATE TABLE and INSERT statements for your sample data, then I could test this.
    This assumes that the combination (pallet, time) is unique. Your sample data includes:
    Pallet          Status          Number          Time
    A          MoveIn          48          11:11
    A          Pick          -1          11:11I assume that you're just not displaying the full time, and your data is really something like:
    Pallet          Status          Number          Time
    A          MoveIn          48          23-Sep-2011 11:11:01
    A          Pick          -1          23-Sep-2011 11:11:08Otherwise, how do you know if these two rows are in te same group or not? You may need to add a tie-breaker to the analytic ORDER BY clause. For example, if you say "ORDER BY time, *status* ", then, if the two rows above really did have exactly the same time, down to the second, then the one with status='MoveIn' would be considered to be earlier than the row with status='Pick'.

  • Results for a period of time (date range)

    Hi,
    Could you please help me with the following:
    SELECT a.lot AS LotNumber, a.codeart AS ItemCode, sum(a.quantity), a.unit AS Unit, a.datetrace AS Dates FROM Production.pps_lotstraces a
    WHERE a.codeart LIKE '886%' OR a.codeart LIKE '997%') and (a.datetrace between to_date('20100105','YYYYMMDD') and sysdate)
    GROUP BY a.lot, a.codeart, a.unit, a.datetrace
    ORDER BY a.lot, a.datetrace
    The only issue I have with this query is that when it is run I get following message
    ORA-01861 - literal does not match format string. This is related to the fact that the date is stored as a string.
    The query should look at the dates from the beginning of the year up to today which is a system date.
    Could you please advise how this issue can be resolved?
    Thank you in advance for your help
    Regards

    user12866679 wrote:
    SELECT a.lot AS LotNumber, a.codeart AS ItemCode, sum(a.quantity), a.unit AS Unit, a.datetrace AS Dates FROM Production.pps_lotstraces a
    WHERE a.codeart LIKE '886%' OR a.codeart LIKE '997%') and (a.datetrace between to_date('20100105','YYYYMMDD') and sysdate)
    GROUP BY a.lot, a.codeart, a.unit, a.datetrace
    ORDER BY a.lot, a.datetrace
    SELECT a.lot AS LotNumber, a.codeart AS ItemCode, sum(a.quantity), a.unit AS Unit, a.datetrace AS Dates
      FROM Production.pps_lotstraces a
    WHERE a.codeart LIKE '886%' OR a.codeart LIKE '997%') and (a.datetrace between to_date('20100105','YYYYMMDD') and sysdate)
                                                        ^
                                                        |
                                                        |
                                                        you have closing parenthesis but you don't have an opening parenthesis
    GROUP BY a.lot, a.codeart, a.unit, a.datetrace
    ORDER BY a.lot, a.datetraceaside from the missing opening parenthesis what is the datatype for your column a.codeart and a.datatrace?

  • Vendor Evaluation in different date Range

    Hi Experts,
    Vendor Evaluation is configured in our client. Our requirement is like this. We want to get vendor evalulation month wise.
    like
    01.04.2009 - 30.04.2009
    01.05.2009 - 31.05.2009
    01.06.2009 - 30.06.2009
    01.07.2009 - 31.07.2009
    How can I get vendor evaluation of a vendor for above period.
    Please guide me, full points for helping answers.
    Regards
    GR

    Hi,
    Check Vendor Evaluation Report tr. ME6H(after selection drilldown on the basis of month), Hope this will work for you
    thanks...

  • Split a query in date-ranges

    DB version 10g
    a sample table is
    my tab
    (dt date,
    status varchar2(2))
    status in ('M','L','H') (medium,low,high)
    sample data are: (date in 'dd-mm-yyy hh24Mi:ss' format)
    DT STATUS
    02-03-2006 08:16:00 H
    02-03-2006 08:20:11 H
    02-03-2006 08:22:00 H
    02-03-2006 08:23:22 H
    02-03-2006 08:24:33 M
    02-03-2006 08:25:44 H
    02-03-2006 08:26:55 L
    02-03-2006 14:27:59 L
    03-03-2006 00:00:00 L
    I'm interested in find duration for every status:
    status H
    from 02-03-2006 08:16:00 to 02-03-2006 08:24:33 => duration 8 min 33 secs;
    from 02-03-2006 08:25:44 to 02-03-2006 08:26:55 => duration 1 min 11 secs;
    status M
    from 02-03-2006 08:24:33 to 02-03-2006 08:26:55 => duration 1 min 11 secs;
    status L
    from 02-03-2006 08:26:55 to 03-03-2006 00:00:00 => duration 15 h ....
    there are a complex query for this purpose without using a procedure that scan all records to find the chenges of status?

    Not very elegant:
    SQL> select * from my_tab;
    DT                  ST
    02-03-2006 08:16:00 H
    02-03-2006 08:20:11 H
    02-03-2006 08:22:00 H
    02-03-2006 08:23:22 H
    02-03-2006 08:24:33 M
    02-03-2006 08:25:44 H
    02-03-2006 08:26:55 L
    02-03-2006 14:27:59 L
    8 rows selected.
    SQL> select status, min(dt), max(ld) from (
      2  select status, dt,
      3  case when lead(dt) over(order by dt) is null then
      4  trunc(dt) + 1 else lead(dt) over(order by dt) end ld,
      5  (row_number() over(order by dt) -
      6  row_number() over(partition by status order by dt)) gr
      7  from my_tab
      8  ) group by status, gr
      9  /
    ST MIN(DT)             MAX(LD)
    H  02-03-2006 08:16:00 02-03-2006 08:24:33
    H  02-03-2006 08:25:44 02-03-2006 08:26:55
    L  02-03-2006 08:26:55 03-03-2006 00:00:00
    M  02-03-2006 08:24:33 02-03-2006 08:25:44Probably a mistake in M example - if I interpret your question right,
    M has to be from 02-03-2006 08:24:33 to the next "H" e.g. 2006 08:25:44 ?
    Rgds.

Maybe you are looking for