Order of records - finding preceding and next records

I have looked around a few forums for a similar question but I'm not really even sure what to search for!
I have a table with some events, client names, timestamps for the event, and a category.  There are four steps in a cycle.
CREATE TABLE #events (EventID INT IDENTITY(1, 1),
Client VARCHAR(10),
RecordTimestamp DATETIME,
Step TINYINT)
INSERT INTO #events (Client,
RecordTimestamp,
Step)
VALUES ('Client A', '01-01-2014', 1),
('Client A', '01-02-2014', 2),
('Client A', '01-03-2014', 3),
('Client A', '01-04-2014', 4),
('Client A', '01-05-2014', 1),
('Client A', '01-06-2014', 2),
('Client B', '01-04-2014', 1),
('Client B', '01-06-2014', 2)
SELECT *
FROM #events
ORDER BY RecordTimestamp, Client
So let's assume that step 2 cannot start for a given client until step 1 completes, category 3 can't start until 2 completes, etc.  If today is 1/7/2014 we could say that Client A has completed one full cycle (steps 1-4), Client A is
half way through cycle 2, and Client B is half way through its first cycle.
I'm trying to identify all cycles that are in progress, meaning a step 1, 2, or 3 is present without a step 4 record (by client).  A query on the data above would return step 2 of Client A and Client B, both on 1/6.  I no longer care about the
first cycle from Client A because another cycle has started.
The table columns can be changed if necessary.  Can someone at least push me in the right direction?  It may involve a CTE and/or cursor, but I'm just not sure where to start.
Thanks!

>  I provided the example above as a slightly simplified version of what I'm working on
Not good, you should provide a something closer to what you are working on.
I read from your original post that "There are four steps in a cycle." and I see that you enumerate them 1 - 4 and also read that "So let's assume that step 2 cannot start
for a given client until step 1 completes, category 3 can't start until 2 completes, etc.", so based on those facts I decided to enumerate all steps for each customer (rn1) and used the formula (rn - 1) / 4 to identify blocks
of steps (groups of consecutive steps):
row                                   rn1  (rn1 - 1) / 4  
('Client A', '01-01-2014', 1)  1    0
('Client A', '01-02-2014', 2)  2    0
('Client A', '01-03-2014', 3)  3    0
('Client A', '01-04-2014', 4)  4    0
('Client A', '01-05-2014', 1)  5    1
('Client A', '01-06-2014', 2)  6    1
('Client B', '01-04-2014', 1)  1    0
('Client B', '01-06-2014', 2)  2    0
Then for each group we enumerate again (rn2) but this time in descending order (rn DESC) so the last step in each group will be the first row based on the new enumeration. Now we can select those rows where rn2 = 1 but only if the step number is not 4.
If your data is different, for example steps numbers go from 10 to 40 in increments of 10 then you have to change the logic slightly:
SET NOCOUNT ON;
USE tempdb;
GO
CREATE TABLE #events (
EventID INT IDENTITY(1, 1),
Client VARCHAR(10),
RecordTimestamp DATETIME,
Step tinyint,
UNIQUE CLUSTERED (Client, RecordTimestamp, Step)
INSERT INTO #events (Client,
RecordTimestamp,
Step)
VALUES
('Client A', '01-01-2014', 10),
('Client A', '01-02-2014', 20),
('Client A', '01-03-2014', 30),
('Client A', '01-04-2014', 40),
('Client A', '01-05-2014', 10),
('Client A', '01-06-2014', 20),
('Client B', '01-04-2014', 10),
('Client B', '01-06-2014', 20);
SELECT *
FROM #events
ORDER BY RecordTimestamp, Client
GO
WITH C1 AS (
SELECT
ROW_NUMBER() OVER(PARTITION BY Client ORDER BY RecordTimestamp, Step) AS rn1
FROM
#events
C2 AS (
SELECT
ROW_NUMBER() OVER(PARTITION BY Client, (rn1 - 1) / 4 ORDER BY rn1 DESC) AS rn2
FROM
C1
SELECT
EventID,
Client,
RecordTimestamp,
Step
FROM
C2
WHERE
rn2 = 1 AND Step < 40;
GO
DROP TABLE #events;
GO
If you can have 8 steps and the maximum one is 80 then the logic should be:
SET NOCOUNT ON;
USE tempdb;
GO
CREATE TABLE #events (
EventID INT IDENTITY(1, 1),
Client VARCHAR(10),
RecordTimestamp DATETIME,
Step tinyint,
UNIQUE CLUSTERED (Client, RecordTimestamp, Step)
INSERT INTO #events (Client,
RecordTimestamp,
Step)
VALUES
('Client A', '01-01-2014', 10),
('Client A', '01-02-2014', 20),
('Client A', '01-03-2014', 30),
('Client A', '01-04-2014', 40),
('Client A', '01-05-2014', 50),
('Client A', '01-06-2014', 60),
('Client A', '01-07-2014', 70),
('Client A', '01-08-2014', 80),
('Client A', '01-09-2014', 10),
('Client A', '01-10-2014', 20),
('Client B', '01-04-2014', 10),
('Client B', '01-06-2014', 20);
SELECT *
FROM #events
ORDER BY RecordTimestamp, Client
GO
WITH C1 AS (
SELECT
ROW_NUMBER() OVER(PARTITION BY Client ORDER BY RecordTimestamp, Step) AS rn1
FROM
#events
C2 AS (
SELECT
ROW_NUMBER() OVER(PARTITION BY Client, (rn1 - 1) / 8 ORDER BY rn1 DESC) AS rn2
FROM
C1
SELECT
EventID,
Client,
RecordTimestamp,
Step
FROM
C2
WHERE
rn2 = 1 AND Step < 80;
GO
DROP TABLE #events;
GO
If you want to show the last non-completed group for each client and from there the first and last steps then try:
SET NOCOUNT ON;
USE tempdb;
GO
CREATE TABLE #events (
EventID INT IDENTITY(1, 1),
Client VARCHAR(10),
RecordTimestamp DATETIME,
Step tinyint
INSERT INTO #events (Client,
RecordTimestamp,
Step)
VALUES
('Client A', '01-01-2014', 10),
('Client A', '01-02-2014', 20),
('Client A', '01-03-2014', 30),
('Client A', '01-04-2014', 40),
('Client A', '01-05-2014', 50),
('Client A', '01-06-2014', 60),
('Client A', '01-07-2014', 70),
('Client A', '01-08-2014', 80),
('Client A', '01-09-2014', 10),
('Client A', '01-10-2014', 20),
('Client A', '01-11-2014', 30),
('Client B', '01-04-2014', 10),
('Client B', '01-06-2014', 20);
SELECT *
FROM #events
ORDER BY RecordTimestamp, Client
GO
WITH C1 AS (
SELECT
ROW_NUMBER() OVER(PARTITION BY Client ORDER BY RecordTimestamp, Step) AS rn1
FROM
#events
C2 AS (
SELECT
DENSE_RANK() OVER(PARTITION BY Client ORDER BY (rn1 - 1) / 8 DESC) AS grp,
ROW_NUMBER() OVER(PARTITION BY Client, (rn1 - 1) / 8 ORDER BY rn1) AS rn2,
ROW_NUMBER() OVER(PARTITION BY Client, (rn1 - 1) / 8 ORDER BY rn1 DESC) AS rn3
FROM
C1
SELECT
EventID,
Client,
RecordTimestamp,
Step
FROM
C2
WHERE
grp = 1 AND 1 IN (rn2, rn3) AND Step < 80
ORDER BY
Client,
EventID;
GO
DROP TABLE #events;
GO
If you check the execution plan you will notice several SORT operators which could yield poor performance. We could try using an intermediate table and adding a POC (partition / ordering / covering - idea from ITzik Ben-Gan) index to improve it.
Does this help?
AMB
Some guidelines for posting questions...

Similar Messages

  • How to find previous and next value of a cursor?

    Im trying to do an update to a table.
    I have a set of rows fetched in a cursor. Now i loop through the cursor and update a field in the table.
    for certain condition alone i need to fetch the previous value in the cursor and update the table with that.
    can anyone let me know if i can fetch the previous and next value of a cursor for this DML operation?
    Thanks in advance.

    You can do it via PL/SQL routine.

  • How can I modify one column of current and next record depending of some criteria?

    Having DDL
    CREATE TABLE #ServiceChange(
    [ID] [int] identity(1,1),
    [SHCOMP] [char](2) NOT NULL,
    [SHCRTD] [numeric](8, 0) NOT NULL,
    [SHCUST] [numeric](7, 0) NOT NULL,
    [SHDESC] [char](35) NOT NULL,
    [SHTYPE] [char](1) NOT NULL,
    [SHAMT] [numeric](9, 2) NOT NULL,
    [CBLNAM] [char](30) NOT NULL,
    [GROUPID] [char](2) NULL
    And original and desire data in below link
    https://www.dropbox.com/sh/bpapxquaae9aa13/AADnan31ZASublDjN7sa2Vvza
    I would like to know how can I modify one column of current and next record depending of some criteria using SQL2012?
    The criteria is:
    Type should always flow F->T
    if current abs(amount)> next abs(amount) then groupid = 'PD'
    if current abs(amount)< next abs(amount) then groupid = 'PI'
    there is no case when those amounts will be equals
    where current(custid) = next(custid) and current(service) = next(service) and groupid is null
    Any help will be really apreciated.
    Thank you

    I tried that and got this error
    'LAG' is not a recognized built-in function name.
    You said you were using SQL 2012, but apparently you are not. The LAG function was added in SQL 2012. This solution works on SQL 2005 and SQL 2008:
    ; WITH numbering AS (
       SELECT groupid,
              rowno = row_number()  OVER (PARTITION BY custid, service ORDER BY date, id)
       FROM   #ServiceChange
    ), CTE AS (
       SELECT a.groupid,
              CASE WHEN abs(a.amount) < abs(b.amount) THEN 'PD'
                   WHEN abs(a.amount) > abs(b.amount) THEN 'PI'
              END AS newgroupid
       FROM  numbering a
       JOIN  numbering b ON b.custid  = a.custid
                        AND b.service = a.service
                        AND b.rowno   = a.rowno - 1
    UPDATE CTE
    SET   groupid = newgroupid
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Previous and Next Record

    Is there any additional code needed to replicate the functionality of the previous and next record buttons in the standard toolbar other than the built-ins that are provided? I'm getting some weird results by just using the built-ins. Thanks!

    Well, to give you and example, when I query the first record and then press the button that uses the previous_record built-in I get the message: at first record (same as the toolbar button). However, when I press the next record button, I'll eventually get the message: field must be entered (whereas, the toolbar button will bring up the message: record must be entered or deleted first). I was wondering why the next_record built-in would bring up a different message, and how to get my button to function the same way as the one in the toolbar.

  • I dropped my mac pro. The disc drive plays but will not record. medium drive error. How hard is it to replace the drive my self. i see screws on the bottom. Could I just order a new internal drive and replace it? Or is it too complicated for the average ?

    I dropped my mac pro. The disc drive plays but will not record. medium drive error. How hard is it to replace the drive my self. i see screws on the bottom. Could I just order a new internal drive and replace it? Or is it too complicated for the average person? Would be cheaper to buy an external drive than to replace internal one? Any advice is appreciated

    How certain are you the superdrive ONLY is at fault?
    That depends on your skill level, if you grew up tearing things apart and putting them together, its absurd how easy it is.
    For some however its too daunting.   On a general skill level for the "average" person its about a 3 out of 10 in difficulty.
    Can you order same? yes.

  • I upgraded to yosemite and iOS 8 in order to record with quicktime. But when I select Record a new movies I immediately get an Operation Could not be completed error.

    I upgraded to yosemite and iOS 8 in order to record with quicktime. But when I select Record a new movies I immediately get an Operation Could not be completed error. When I choose record audio or screenshots, I get a little further, but as soon as I select my ipad as the source I get the same error message.

    You don't need to be a developer for this to work. I get the same error. Just one more thing on the list that make me upset more and more with Apple. Things just don't work out of the box like they used to.
    This new feature was to be included with iOS 8 and Yosemite.

  • Java executeBatch() - Problem in INSERT (Order of  records not maintained)

    When we make a executeBatch() . And when the use
    select * from DUMMY_FILE_S order by ROWID
    or
    select * from DUMMY_FILE_SThe rows returned are in different order.( that is its not in the order what is inserted actually)
    And this happens once in a While.
    This is will happen only if we try many times also So please try with many INSERTs
    Please find the Java Code and the Insert SQL.
    import java.sql.Connection;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.io.*;
    import java.sql.DriverManager;
    public class warranty_dummy
         public static void main(String args[])
                String FILENAME = "D:/data.sql";
                Connection conn = null;
                //String db_file_name_prefix = "@localhost:1531:xxxx_y14";
                   try {
                       Class.forName("oracle.jdbc.OracleDriver").newInstance();
                       // DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
                        catch (ClassNotFoundException e) {
                               e.printStackTrace();
                               //System.out.println("INSIDE class forname :"+ e.getStackTrace());
                   }catch(Exception e){
                        e.printStackTrace();
             try{
                    conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1531:yyyy_xxxx","my_user","password");
                 Statement stmt = conn.createStatement();
                   BufferedReader in = new BufferedReader(new FileReader(FILENAME));
                 String line = in.readLine();
                 System.out.println("Line " + line);
                  while(line != null) {
                 System.out.println("Line 1" + line);
                   stmt.addBatch(line);
                 line = in.readLine();
                 System.out.println("Outside While");
                 in.close();
                 int iarray[] = stmt.executeBatch();
                 System.out.println("Count" + iarray.length);
                 catch (Exception e ){
                         System.out.println("Error attempting to store results for batch " + e.getMessage());
                     } finally {
                         try {
                             conn.commit();
                             conn.close();
                         } catch (Exception se) {
                             System.out.println("Error attempting to store results for batch "+ se.getMessage());
    }SQL Data sample
    INSERT INTO DUMMY_FILE_S (FILE_NO,S_NO) values (44444,'123456789')
    INSERT INTO DUMMY_FILE_S (FILE_NO,S_NO) values (44444,'567891234')
    INSERT INTO DUMMY_FILE_S (FILE_NO,S_NO) values (44444,'333333333')
    INSERT INTO DUMMY_FILE_S (FILE_NO,S_NO) values (44444,'323232323')

    Thanks for your prompt reply.
    If we even use ORDER BY clause, we still don't get the records in the order what we inserted.
    And we see that the problem is in smt.executeBatch(); is not inserting the records the way its inserted
    For Example.
    if we insert
    INSERT INTO MyTable (SERIAL_NUMBER, DESCRIPTION ) VALUES (1,"test1");
    INSERT INTO MyTable (SERIAL_NUMBER, DESCRIPTION ) VALUES (2,"test2");
    INSERT INTO MyTable (SERIAL_NUMBER, DESCRIPTION ) VALUES (3,"test3");
    INSERT INTO MyTable (SERIAL_NUMBER, DESCRIPTION ) VALUES (4,"test4");Note : (Using smt.executeBatch();)
    After that when we use
    Select * from MyTable ORDER BY ROWIDFor some time we get the result of the query as ( In the order we Insert )
    SERIAL_NUMBER, DESCRIPTION
    ==========================
    1,test1
    2,test2
    3,test3
    4,test4And For some time we get the result of the query as ( We don't get the records in the order we Insert )
    SERIAL_NUMBER, DESCRIPTION
    ==========================
    1,test1
    3,test3
    2,test2
    4,test4Is there any work around for this?
    Thanks in advance

  • Find Planned and Production Orders

    Hi all ,
    I have a requirement . If i give the Work center Name i should get already assigned Planned Orders or Open Production Order against that Work center .
    Please let me know . If there is no standard FM then let me know can i retrieve those from any tables .
    I appreciate for any suggestions .
    Regards
    Raj

    Hello Raj
    Please note that your "objective" (Find planned and Production Orders) has little to do with object orientation.
    Function module BAPI_ALM_ORDEROPER_GET_LIST is probably the one you are looking for. You need to feed TABLES parameter IT_RANGES with the appropriate values.
    Please note that the selection parameters have special names that can be found in the structures defined in fm IBAPI_ALM_ORDEROPER_GETLIST:
    * set some local constants:
      constants:
        lc_progname like rsvar-report value 'RIAFVC20',
        lc_par_int  type ddobjname value 'IBAPI_ORDER_LISTOPER_PARAMS',
        lc_par_ext  type ddobjname value 'BAPI_ALM_ORDER_LISTOPER_PARAMS',
        lc_sel_int  type ddobjname value 'IBAPI_ORDER_LISTOPER_SELOPS',
        lc_sel_ext  type ddobjname value 'BAPI_ALM_ORDER_LISTOPER_SELOPS'.
    Example: If you want to select for a specific work center then I assume the selection parameter is:
    (BAPI_ALM_ORDER_LISTOPER_SELOPS-) OPTIONS_FOR_WORK_CNTR
    Thus, to select for a given work center add the following record to IT_RANGES:
    FIELDNAME = 'OPTIONS_FOR_WORK_CNTR'   " presumably without the DDIC structure name
    SIGN = 'I'
    OPTION = 'EQ'
    LOW = <work center>
    If the selection does not work then just do a little debugging.
    Regards
      Uwe

  • Retrieve the Purchase Order Condition Records Table

    Hallo!
    I have found this code right here:
    http://www.sap-basis-abap.com/sapab025.htm
    It is very useful particular for purposes which I need. Please can somebody
    try to fix the error to get it working. There is an internal table missing.
    Regards
    Ilhan
    Retrieve the Purchase Order Condition Records Table
    select * from ekko.
           select * from konv where knumv = ekko-knumv
               "Get all the condition records for the purchase order
           endselect.
    endselect.
    * Get the info record conditions record
    * First declare the record structure for the key
    data: begin of int_konp,
                 txt1(5),
                 lifnr(5),
                 matnr(18),
                 txt2(4),
                 txt3(1),
            end of int_konp.
    clear: konh, konp, int_konp.
    * data for the record key konh-vakey
    int_konp-txt1    = '00000'.
    int_konp-lifnr    = ekko-lifnr+5(5).
    int_konp-matnr = ekpo-matnr(18).
    int_konp-txt2    = 'ALL'.
    int_konp-werks = ekpo-werks.
    int_konp-txt3    = '0'.
    select * from konh where      kschl = 'PB00'            "Conditions (Header)
                                         and datab => p_datum.       "valid from date
          if konh-vakey = int_konp.                                  "Conditions (Item)
                 select single * from konp where knumh = konh-knumh.
                 continue.
          endif.
    endselect.

    Hi flora
    Just get through the sequence .
    see the table fields ...
    1. From EKKO table take an entry which is having pricing conditions.
    Now in the fields list check out for field EKKO-KNUMV(document condition number).
    2.Take this condition number and now goto table KONV.
    Give the document condition number in the field  KONV-KNUMV and execute .
    This will lead to a list of document condition numbers and some other fields .
    3.Now check for field KONV-KNUMH ,KONV-KAWRT(quantity) and note the value KONV-KWERT  .
    (Remember this is at header level).
    This is ur condition record number.
    **comments
    Now from document condition number we got the condition record number (KNUMH).
    4. now since u want the item level tax procedure go to table KONP and give the condition record number and execute .
    This will give u a list of details .
    Now concentrate on KONV-KAWRT (scale quantity) KONP-KBETR(rate) as this table will store “Pricing  per UNIT “ so product of these two will give u the total pricing tax, for a particular condition type say PR00  .
    For that particular condition item .
    Check the pricing procedure .
    See t-code VK13 and check the pricing procedure .
    From me23 check the same PO num select the item and check the pricing conditions applicable .
    Select a particular pricing and goto condition->analysis->analysis pricing  ,
    Better take help of a SD functional consultant in the process.
    regards,
    vijay.

  • Regarding Purchase order info records

    Hi,
    How do I read the text maintained against purchase order info records, transaction ME12. What is the key that I should use for reading the text maintained.
    Regards,
    Vijay

    it may differ from system to system, so i will tell you how i determined this, rather than what i determined.
    In your development or test system, make a change to the text.
    now, use SE16 and look at table STXH. Put todays date in the TDLDATE selection (and your id for TDLUSER, if you want)
    You should see the changes you made, and the keys associated with the texts. you can then use the FM READ_TEXT to get the text...
    Hope this helps

  • Internet required in order to record - privacy iss...

    While my girlfriend is watching something online or playing her online games..I have noticed that I am unable to record any programs and instead get an error message.  As soon as she stops using the internet I can record just fine...she starts using it again and I cant record.
    I thought this was very odd so I did a little test and switched off my internet completely and again I was unable to record anything..so I switched my internet back on again and I WAS able to record.
    There is also a noticeable delay from when I press the record button to when I see the recording confirmation message so because the internet is required and because of this confirmation delay it leads me to believe that my box is sending some information through my internet connection to BT of the programs I am recording.
    Is this true??..if it is true then why does BT need to know what I am recording and how do I opt out of the spyware???
    If its not sending any information then why do i need to be connected to the internet in order to record anything..the programs are coming through my ariel and recorded directly to my box so at no point is the internet required so why???

    maxrpg wrote:
    No I never disconnect my vbox or anything.  I seems that when theres lots of internet activity like watching streaming videos online and/or playing MMO games it will not allow recordings but it works fine when activity is low.  I always thought vision and standard BB were seperate and that they didnt impact on eachother?
    Yes but why do my recording schedules need to be stored on BT servers and what does BT do with this information.  surely the box can store my schedule.
    It just seems odd to me and I cant think of any reason why it needs to be stored on a server instead of my box :\
    For the functionality we have now, and for the last 4 years, there is very little point in having this record of the recordings (past and present - you won't be able to delete things either) on their servers. There is some useful functionality that would benefit from it - the most obvious being multi-room, another being remote access (say from your phone) to modify your scheduled recordings. But as we don't have these features there's only one time when this comes in useful - when you do a factory reset which deletes everything on your box. Not being able to make or delete recordings without access to the Vision servers is, at present, a royal pain in the bottom.
    I've never heard of internet usage contention causing the vbox to have no access to the servers. Possibly your hub is faulty. Try rebooting it, or better giving it 15 minutes powered off, or best yet doing a factory reset of the home hub and see if that makes a difference.

  • Order of records in o/p  of select statement

    Hi all
    I have doubt regarding the select statement. I need to execute a select statement (with out any order ie with out "order by") which searchs a table. I want to know whether in any
    circumstances the order of the records of the select statement is different.
    sample select statement which I need to execute
    select emp_no from emplyees where designation = 'programer'
    in one word order of records of in the o/p of a select statement will be unique ?
    (provided same query same, table,)
    can u plz quote the link to get more information
    regards
    Renjith

    Hi,
    YES, you can
    Do Order By Without Using Order By Clause
    in your select statement.
    I assume that you have unique data ( e.g. emp_no in Emp Table ) and you you do not want to use Order by clause.
    Solution 1:
    Select Emp_no
    from Emp
    group by Emp_no;
    the o/p will be in the sorted in the Ascending order.
    Solution 2: ( Only for columns holding Numeric Values )
    Select Emp_No
    From Emp
    Where 99999 - Emp_no in ( Select 99999 - Emp_no from Emp );
    Again this will sort the result will be in the Descending Order. you can use any big number instead of 99999 but it should be greater than Emp_no value.
    Note: You Should only use this method on not very large tables coz of performance issue.
    Hope this will solve your problem.
    Any Comment on this, any body.
    Thanks and Regards
    There is always a solution to the problem, And if there is no solution of a problem then problem is not a problem.

  • Ordering the records prior to select

    I have a table 'orderlines' with columns line_id, ship_flag, service_flag, bom_order.
    I need to generate the order line number in the following way
    select the orderlines order by bom_order
    for the first line the line number is 1.0
    for the next line if ship_flag is 'Y' then line_number is 1.1 else the line number is 2.0
    for the next line if the previous line ship_flag was ' Y' and service_flag is 'Y' then line number is 1.1.1 else
    if ship_flag is 'Y' then line number is 1.2, else 3.0
    so we have a package UTIL and function get_number where there is a global variable to capture the previous numbers (line number, ship number and service number) and based on the flag increment appropriate number and generate the line number as varchar2.
    I create a view
    create or replace view order_with_lineno is
    select line_id,
    util.get_number(ship_flag, service_flag) as line_number,
    from orderlines order by bom_order;
    This view doesnot give me the correct line_number, becaue the sorting happen after the line_number generation is done.
    can someone give me a solution for this?

    This is making some assumptions about how your flags are set, but if the data looks like the following, you can use a query for this:
    create table orderlines
    bom_order number,
    line_id number,
    ship_flag varchar2(1),
    service_flag varchar2(1)
    delete from orderlines;
    insert into orderlines values (1000,10,'N','N');
    insert into orderlines values (1000,20,'Y','N');
    insert into orderlines values (1000,30,'N','Y');
    insert into orderlines values (1000,40,'N','Y');
    insert into orderlines values (1000,50,'Y','N');
    insert into orderlines values (1000,60,'N','Y');
    insert into orderlines values (1000,70,'N','Y');
    insert into orderlines values (1000,80,'N','Y');
    insert into orderlines values (2000,10,'N','N');
    insert into orderlines values (2000,20,'Y','N');
    commit;
    SELECT bom_order,
           line_id,
           l1||'.'||l2||decode(l3,0,'','.'||l3) new_line_id
    FROM   (
            SELECT bom_order,
                   line_id,
                   l1,
                   l2,
                   sum(decode(service_flag,'Y',1,0)) OVER (PARTITION BY bom_order,l2 ORDER BY line_id  ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) l3
            FROM
                    SELECT bom_order,
                           line_id,
                           service_flag,
                           dense_rank() OVER (ORDER BY bom_order) l1,
                           sum(decode(ship_flag,'Y',1,0)) OVER (PARTITION BY bom_order ORDER BY line_id  ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) l2
                    FROM   orderlines
    BOM_ORDER    LINE_ID NEW_LINE_ID
          1000         10 1.0
          1000         20 1.1
          1000         30 1.1.1
          1000         40 1.1.2
          1000         50 1.2
          1000         60 1.2.1
          1000         70 1.2.2
          1000         80 1.2.3
          2000         10 2.0
          2000         20 2.1Greg Pike
    http://www.singlequery.com
    Message was edited by:
    gfpike
    Had a raw data error.

  • Ordering of records after export

    I have a peculiar probelm, the order of records changes when exporting data (by dump) from one machine to another. Both are different type of laptop m/c. Both uses personal Oracle. Presently we are not able to simulate the same problem because of the lack of setup.

    Hi Katie,
    Click on "Library" and then you should see some columns on the top of the window, just like "Name", "Album", "Time", "Genre"... Just click one time over the "Album" column and all your songs will change to the correct order...
    Hope it helps.

  • ASCp - Planner Workbench, PO in receicing order type record

    Dear Friends,
    In ASCP, Planner Workbench ,under a plan, supply and ddemand screen has an order type "PO in receicving" with firm flag enabled with future date for due dates
    We could see all the PO's for that item is closed. On hand Quantities also got increased based on that PO receipts.
    Can you please let me know, what does that mean by "PO in receicving" order type record and how for a closed PO's it is being shown?
    Thanks,
    Ganesh

    Hi Ganesh,
    The closed PO's should not be there and shouldn't have PO in Receiving status either.
    But the reason why you must be seeing this is because there is still a record in MTL_SUPPLY for this PO with supply type code as RECEIVING and hence its still
    appearing in ASCP.
    Please go by the below article if the supply is still shown in RECEIVING but PO's are completed and run the mentioned queries to diagnose and get the inventory transaction fixed.
    Fully Received / Delivered / Finally Closed Po Line Still Appearing in Item Supply / Demand Form MS and RS (Doc ID 1364291.1)
    Moreover, if you started seeing this issue more often then the best way is to put the piece of code in the collections hook i.e MSC_CL_CLEANSE API to purge the supplies from ODS if PO's are closed for those.
    Thanks,
    Abhishek Sharma
    Please mark the post correct or helpful, if answered

Maybe you are looking for

  • Cannot resize main partition

    I installed Bootcamp and obviously Bootcamp Assistant reduced my main partition so that it could create a new one for me to install Windows on.  I finished my project and decided I wanted the space back.  Something must have gone wrong when the Bootc

  • Submitting a feed to Itunes

    When I submit my feed http://www.quoteactionspodcast.com/?feed=podcast, I get the following error message: We had difficulty reading this feed. Bad http result code: -1 I can't find what this is or how to solve the problem

  • Why is httpwebrequest result different from page source viewed through browser?

    I am trying to use httpwebrequest to download the page source code from Yahoo Finance pages, e.g., https://ca.finance.yahoo.com/q/op?s=AA&m=2015-04 The httpwebrequest method returns much less information than the page returned by using "page source "

  • IDE integration support

    Hi I'm trying to find the best IDE to use with WLS and are struggling a bit. I've been trying to select IDEs for WLS development for quite some time now (and for several projects), and I've always concluded that none of the IDEs support a tight enoug

  • Dreamweaver CC How to make emails

    How do I make a button that sends an Email of a form I made! Here is the code! <!doctype html> <html> <head> <meta charset="utf-8"> <title>Custom Plugin Made</title> </head> <body> <p><font size="+33" color="#FF0000"> <b>What Plugin Do you want to be