Updating only the last record.

Hi,
I have a scenario where we get more than 1 record based on style. Everytime the new record comes in, I need to update the last record inserted. It requires a procedure to do it, but need some help on how to just update the last record only and not all the previous received records.
Here is the scenario.
create table test_1 as
with data_Set as
( select 'ABCD' style, 20080101 date_received, 2 duration,20080301 expire_Date from dual union all
select 'PQRS' style, 20080201 date_received, 2, 20080401 expire_Date from dual
) select * from data_set
so now on next run when i get another record
insert into test_1
select 'ABCD' style, 20080401 date_received, 3 duration,20080701 expire_Date from dual.
now the procedure should insert the incoming record and also update the expire_date for the previous record to a day before date_received for the new record. I am ok doing it when its only 2 records , but when i get another record of same style, i dont want to update all the previous received records. I only want to update the last record on file.
can anyone suggest?

STYLE     DATE_RECEIVED     DURATION     EXPIRE_DATE     SEQ_INSERTED
110427     7/31/2006     0     7/31/2006     2
110427     9/1/2007     12     9/1/2008     2
110427     8/2/2008     24     8/2/2010     3
468130     3/13/1997     0          2
468130     3/13/1997     12     3/13/1998     2
468130     1/12/2008     12     1/12/2009     3
Here is my data set
and here is the query i use to update, does it look correct?
update test b
set ( expire_Date) =
(select start_date - 1
from test a
where (style_no, date_received) in
(select style_no, max(date_received)
from test c
group by style_no
and a.style_no = b.style_no
and style_no in ('468130','110427')

Similar Messages

  • Display only the last record per material in SAP query

    Hi,
    I have created a SAP Query using the quickviewer that is a join between 2 tables (MSEG and MKPF) that consist of material document information and date of posting.
    The results are fine however I would like only the last record per material to be displayed.
    Can anyone tell what do I need to add so for only the last record per material be displayed in the output.
    Thanks,
    Mark

    Hi Mark,
    May be if you use Control Level processing .........I think you will be able to get the result you want. Try displaying as Below,
    LOOP AT XXXXX.
    AT FIRST material.
    ENDAT.
    AT LAST material.
    *...Display what ever you want here. It will display at end of every material.
    ENDAT.
    ENDLOOP.
    Before using sort the table with key material in ascending.
    Hope what I had to say is helpful to you.
    Cheers,
    Raga Suman.

  • Only put the last record retreived into the item form

    Hi All,
    I am trying to show all the retreived records of a query in a multi-line formTEXT item. However, it seems to me that only the last record shows rather than all records. The code is below where DM_AR is a package and OPEN_R_TYPE, Fetch_data are two procedures which uses a cursor variable. The below code runs perfectly in SQLPLus if we replace the :RESULT_TEXT := .., with a DBMS_output.put_line build-in procedure.
    Any suggestion Plz......
    F
    DECLARE
    -- declare a cursor variable
    RES DM_AR.ruleitem_type;
    TEMP_row TEMP_TBL%ROWTYPE;
    BEGIN
    -- open the cursor using a variable
    DM_AR.OPEN_R_TYPE(RES, :MODEL_NAME);
    -- fetch the data and display it
    LOOP
    DM_AR.Fetch_data(RES, TEMP_ROW);
    EXIT WHEN RES%NOTFOUND;
    :RESULT_TEXT := 'RuleNo: ' || TEMP_ROW.RULE_ID || ' Conf: '|| TEMP_ROW.R_CONF || 'Supp: ' || TEMP_ROW.R_SUPP || ' IF: ' || TEMP_ROW.ANTECEDENT || ' THEN: ' || TEMP_ROW.CONSEQUENT;
    END LOOP;
    END;

    You are overwriting your item :RESULT_TEXT everytime in the loop. So, you only see the final result. You probably want this:
    :RESULT_TEXT := :RESULT_TEXT || ' RuleNo: ' || ...
    ...

  • How to get the last record??

    Hi, I now have to get only the last record from one table
    from MS Access.
    I was looking for the useful method from API, however,
    I cannot get it.
    How to get only the last record from one table ???
    Please help, thanks.

    In RDBMS, row order is really not relavent by iteself. Meaning there is no such thing as 'last record' unless it's in the context of a column (e.g. timeStamp).
    Of course, rows are inserted and stored in some natural order, but you cannot assume they'll come back the same way in a 'Select *' as they were entered.
    So, if you mean last row as in last inserted row, I would add a timestamp field that's set at insert, or use a autonumber column. Either way, have a column that will always contain the highest number or newest timestamp, and then you can build your where clause from that.
    For instance, in Access, I have an autonumbered field called 'fred', with other columns. If I want the last record, I simply use the following:
    select * from atable where fred in (SELECT max(fred) AS Max FROM atable);
    the 'where in' clause will filter to only those records in the subsequent select statment, which of course is only one, the max of the column fred.
    bRi

  • How to get the only the last raw of the table

    Hello All,
    While fetching a table into internal table, how to get only the last record of the table.?
    Thanks and Regards, Pradeep

    I hope following code will solve your problem.
    DATA : it_bseg TYPE TABLE OF bseg,
           x_bseg TYPE bseg,
           v_index TYPE i.
    SELECT COUNT(*)
      FROM bseg
      INTO v_index.
    SELECT *
      FROM bseg
      INTO TABLE it_bseg.
    READ TABLE it_bseg INTO x_bseg INDEX V_INDEX.
    First SELECT will give you the number of rows in a table in v_index. Second SELECT will fetch all table data and then READ will give you the last record of the table in a structure x_bseg.
    Reward points if the answer is helpful.

  • Selecting the last record from a database table

    In my ABAP Program, I have to use a select statement to retrieve the last record from the database table with the same key.  In other words, the Program will get more than one hit on the database table for the selected keys and I need to retrieve values from only the last record and not the first.  I know I can use an internal table to sort the records first and then retrieve the right value.   But to make things easier, is there a SELECT statement keyword than I can use to do this in one single step?  Thanks!

    hi,
    tables:mara.
        data: begin of it_mara occurs 0,
                matnr like mara-matnr,
                meins like mara-meins,
                mtart like mara-mtart,
                end of it_mara.
    select-options:s_matnr for mara-matnr.
    select matnr
              meins
              mtart
    from mara
    into table it_mara
    where matnr in s_matnr.
    if not it_mara[] is initial.
    sort it_mara by matnr descending.
    read table it_mara index 1.
    endif.
    then you get the last record of the select statement.
    reward points if useful,
    venkat.

  • RFC - XI - JDBC(mapping only the last row of a record)

    Hello all,
    in a mapping response from an oracle base after a RFC call with a select statement, i have the following response :
    <StatementSelect_response>(cardinality 0..1)
    <row1>(cardinality 0..unbounded)
    <field1>1</field1>
    <field2>2</field2>
    </row1>
    <row2>
    <field1>3</field1>
    <field2>4</field2>
    </row2>
    </statement>
    i have to map those fields in a RFC_response like :
    <RFC_response>(0..1)
    <field1>
    <field2>
    </rfc _response>
    Problem : I only need to send back to the rfc_response the last records of my StatementSelect_response in order to have the following message :
    <RFC_response>
    <field1>3
    <field2>4
    </rfc _response>
    How can i select only the last row of my records plz ?
    Thanks by advance

    VJ wrote:>
    > Hi,
    >
    > public void LastRow(String[] a,ResultList result,Container container){
    >
    > int len = a.length();
    > Result.addValue(a\[len-1\]);
    >
    > }
    VJ,
    Please don't confuse him. If you want to update the thread, let me leave it aside.Coz it shouldn't cause him trouble. Can u check a.length() is correct? it has to be a.length, isn't it?
    We all here to help others, not under any motivation of compete..
    Sorry, if I hurt you..
    raj.

  • I have an iBook G4 and iTunes is no longer updating. The last update is 9.2.1 but it doesn't support my iPhone or iPad. Is there anything I can do to update iTunes or is my only recourse to update my laptop?

    I have an iBook G4 and iTunes is no longer updating. The last update is 9.2.1 but it doesn't support my iPhone or iPad. Is there anything I can do to update iTunes or is my only recourse to update my laptop?

    As Niel has suggested Mac OS X 10.5 Lepaord.
    But first of all make sure that your iBook is above 800Mhz and you have at least 512 Meg of memory. (1 GB recommended)
    Please note, that if you do install Mac OS X 10.5 on your iBook, it will not allow you to install the latest version of iTunes version 11. The most recent version of iTunes that can be installed would be 10.5, which will be compatible with your iPod touch 4th gen, provided it's not been updated to iOS 6.
    Sadly you can't install any version of Mac OS X above 10.5 Leopard, as it they requires an Intel processor, which your iBook G4 does not have.
    Hope this helps.

  • Function in select statement need to be called only for the last record.

    Select state,
    local,
    fun_state_loc_other_details(19) details
    from state_local
    where pm_key=19
    resuts:_
    State Local Details
    AP APlocal details1
    UP UPLocal details1
    MP MPLocal details1
    i) The above query returns 100 records
    ii) fun_state_loc_other_details is also getting called 100 times. But I want this function to be called only for the last record that is 100th record.
    is there any way to do that?

    Thanks amatu.
    One more small query. Can I do it on condition based.
    Select state,
    local,
    fun_state_loc_other_details(19) details
    from state_local
    where pm_key=19
    Like if one state it need to be called once.
    AP -- 50 records
    UP - 20 records
    MP -- 10 records.
    fyi: this record no. varies
    I want the function to be called for AP once, UP once, MP once.

  • When I send mi presentation to a Quick Movie, the program record only the last frame

    Why when I send mi presentation to a Quick Movie, the program record only the last frame, how I do to record the whole presentation of 52 frames

    I mean when I try to burn a CD.

  • Not enough space to print the last record on each page

    Hello,
    My report looks like a simple list table, with the first row as the column header, followed by rows of records.
    The fields are placed on the Detail section and they're set with "Can Grow" property. That means, records may have different row height, some may take 1 row per record, some may take 3 rows per record, depending on the data length. I use some vertical lines on the Detail section as the column seperators, and a horizontal line as the record seperator.
    I've a Page Footer to show the page number and print date.
    My problem is:
    When the space of the last record on the current page isn't big enough, the record will be printed automatically on the second page, which is fine. But the vertical seperation lines are still displayed even though the details are printed on the second page. I got some "empty rows with vertical seperation lines" or I'd say an open-end table at the end of some pages then.
    Is there a way to avoid this?
    Your help is much appreciated. Thank you.
    Agnes

    You could draw an outline box from page header to page footer, then your internal lines would run from page header to page footer
    so if the document extends to 2 pages, the page footer will print on the 1st page and therefore the bottom line of the box
    only problem now would be that on the 2nd page the box will extend to the bottom of that page also, even if there is only 1 record

  • How to get the last record from the database

    I am using MS Access database and Swings as GUI. I want to get the last record of a particular column from the table and store it as a varaible.

    Hi
    To get Last record of resultset, you have pass some parameter in constructor of CreateStatement.In such case Resultset should be scrollable and Readonly
    Example
    objStatement=objCon.createStatement ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
    mwwResultSet=cwwStatement.executeQuery(mwwSqlQuery);
    while(mwwResultSet.next())
    if(mwwResultSet.isLast())
    //Fetch the required column record.
    String abc=mwwResultSet.getString(1);
    I think this will work. Try it.
    bye

  • How to get the last record of an internall table ....

    Hi All..
    i want to get the last record of an internal table itab, and i want the the value of the last record.

    Hi,
         Use describe statment.
    data: lv_line type i.
        Describe table itab lines lv_line.
        read table itab into wa_itab index lv_line.
    regards,
    Santosh Thorat

  • How can I get only the last 2 rows?

    How can I narrow down a query to get only the last two rows in a table ?
    Thanks,
    Mohan

    Thanks a lot Ram for your suggestion but already I have a query which returns a set of rows, of which I would like to further filter and get the last two rows
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Ramanuj Bangad ([email protected]):
    try out something like this if it helps.
    Example:
    select * from users
    where rownum <= (select count(*) from users)
    minus
    select * from users
    where rownum <= (select count(*) -2 from users )
    <HR></BLOCKQUOTE>
    null

  • How to get the first and the last record of every month within a time range in sql

    I am trying to get the first record and the last record of each and every month in a given date range using sql. I have a sample code
    where i have just selected everything within the date range now i have to extract the first and the last records of each and every month.
    SELECT PurOrderNum,
    OrderDate
    FROM Purchasing.PurOrder
    WHERE OrderDate >= '2013-02-28'
    AND OrderDate <= '2014-12-29'

    SELECT PurOrderNum,
    OrderDate
    FROM
    SELECT PurOrderNum,
    OrderDate,
    MAX(OrderDate) OVER (PARTITION BY DATEDIFF(mm,0,OrderDate)) AS MaxDate,
    MIN(OrderDate) OVER (PARTITION BY DATEDIFF(mm,0,OrderDate)) AS MinDate
    FROM Purchasing.PurOrder
    WHERE OrderDate >= '2013-02-28'
    AND OrderDate <= '2014-12-29'
    )t
    WHERE OrderDate = MaxDate
    OR OrderDate = MinDate
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

Maybe you are looking for

  • How do I display a message in the message area of a report with SALV?

    Hi, How do I display a message at the bottom of the screen of a report (don't know the correct name for the area, but it's the area where error messages normally appear) using the CL_SALV_TABLE object model? Is there a method in the object model some

  • F110 aborted in midway through processing

    Hello. While running F110 this morning, it aborted and some document were cleared and others didnt clear. 2 things I can possibly do and I need everyone's input on the best solution. I can either processes the document with clearing document number a

  • Oracle.exe consuming 100% CPU on windows and database hang

    Hi all, every time my oracle database is hanging when the application run, the problem is the oracle.exe consum 100% CPU but not memory and the server hang and the dabase is going to inaccessible, we need to restart oracle instance service or server

  • Applescript on Numbers to copy rows between tables

    Hi, I am an applescript newbie, but am trying to make my book-keeping spreadsheet a bit more comfortable. And this is the problem: I have expenses that repeat every month and I would like to not have to rewrite them each time. So I thought I make a s

  • Cannot resolve symbol readShort

    Could someone please tell me what I am doing wrong. I am trying to read a binary file in which the elements are stored in 16 bit integers. When compiling, I get the error create2.java:34: cannot resolve symbol symbol : method readShort (short) locati