Update New Record

T1::
C1
C2
C3
T1
C1   C2    C3
A    100   1
A    108   2
B    104   1
B    106   2
Insert New record
Insert Into T1(C1,C2,C3)
Values(A,105,NULL);
Insert Into T2(C1,C2,C3)
Values(A,105,NULL);
Declare
Begin
For i in (select T1.C1 from T1,T2 Where T1.C1=T2.C1)
Loop
Update T1
Set C3=(Seelct Rn From
select ROW_NUMBER() OVER(Partition By C1 oder by C2 ) Rn from T1 where 1=i.C1
Where C1=i.C1
And C2=i.C2;
End loop;
End;
Is this update correct to make above sample data to
T1
C1   C2    C3
A    105   1         ---------------------> Inserted New Updated with 1
A    100   2         ---------------------> Old with C3=1 Now C3=2
A    108   3
B    104   1
B    106   2

Or for the update part, you could do this:
update t1 set c3=(case when c3 is not null then c3+1
                        when c3 is null then 1 end)
          where c1 =:c1;You are 'oder by C2' while C2 is not really in the order (105, 100, 108).
Here is the detail:
create table t1 (c1 varchar2(1), c2 number(3), c3 number(3));
insert into t1 values ('A',100, 1);
insert into t1 values ('A',105, NULL);
insert into t1 values ('A',108, 2);
insert into t1 values ('B',104, 1);
insert into t1 values ('B',106, 2);
insert into t1 values ('B',110, null);
CREATE OR REPLACE PROCEDURE TEST AS
  CURSOR c1
  IS
    SELECT DISTINCT C1 FROM T1;
BEGIN
  FOR item IN c1
  LOOP
    UPDATE t1
    SET c3=(
      CASE
        WHEN c3 IS NOT NULL
        THEN c3+1
        WHEN c3 IS NULL
        THEN 1
      end)
    WHERE c1 =item.C1;
  END LOOP;
END TEST;
select * from T1 ORDER BY C1, C3;
A     105     1
A     100     2
A     108     3
B     110     1
B     104     2
B     106     3Edited by: PhoenixBai on Aug 30, 2010 12:47 PM

Similar Messages

  • Performance issue in update new records from Ekko to my ztable

    I'm doing changes to an existing program
    In this program I need to update any new purchase orders created in EKKO-EBELN to my ztable-ebeln.
    I need to update my ztable with the new records created on that particular date.
    This is a daily running job.
    This is the code I wrote and I'm getting 150,000 records into this loop and I'm getting performance issue, can Anyone suggest me how to avoid performance issue.
    loop at tb_ekko.
        at new ebeln.
          read table tb_ztable with key ebeln = tb_ekko-ebeln binary search.
          if sy-subrc <> 0.
            tb_ztable-ebeln = tb_ekko-ebeln.
            tb_ztable-zlimit = ' '.
            insert ztable from tb_ztable.
          endif.
        endat.
      endloop.
    Thanks
    Hema.

    Modify  your code as follows:
    loop at tb_ekko.
    at new ebeln.
    read table tb_ztable with key ebeln = tb_ekko-ebeln binary search.
    if sy-subrc <> 0.
    tb_ztable_new-ebeln = tb_ekko-ebeln.
    tb_ztable_new-zlimit = ' '.
    append tb_ztable_new.
    clear tb_ztable_new.
    endif.
    endat.
    endloop.
    insert ztable from table tb_ztable_new.
    Regards,
    ravi

  • Update new record in database table

    I'm working with TestStand 4.2 and MySQL database with user-defined tables.
    There is "test_results" table with autoincrement "id" (primary index).
    I want to:
    1. write a new record to the test_results table - some data and status "Running"
    2. run a test (pass to a test sequence its "id", test uses this id for writing data to database)
    3. update the record: set execution time and update status.
    So, the steps are as below:
    1. Open database
    2. Open SQL statement: "select * from test_results".
    3. Data Operation: operation - "Set and Put", record to operate on - "New - Create New Record". In the "Column/Parameter Values" tab I set the new record values.
    Here I want to retrieve the new record "id". How to do it?
    Thanks in advance.

    I am not sure how to implement this in Test Stand, but from an SQL programming perspective, you want to run:
    SELECT @@IDENTITY
    Here is a link to the description:  http://msdn.microsoft.com/en-us/library/ms187342.aspx
    It will retrieve the record ID of the row you just inserted.

  • Update new records and delete old record? Urgent

    Iam updating some records from internal table to Data base table.
    Please suggest me
    INSERT DBTable FROM TABLE itab.     
    UPDATE DBTable FROM  itab.
    Delete existing records.
      DELETE  DBTable FROM TABLE itab_old.
    Please suggest me

    Got you..
    Iam colecting some records to internal table from Data base table
    based on year and month.
    Then changing the date and months in interenla table
    then inserrting this modified records of internal table into datta base table.
    Finaly delete the old records with old dates.
    Here is the suggestion..This is a logic and not the exact code..
    DATA: ITAB TYPE STANDARD TABLE OF ZTABLE WITH HEADER LINE.
    DATA: ITAB_OLD TYPE STANDARD TABLE OF ZTABLE WITH HEADER LINE.
    SELECT * FROM ZTABLE
           INTO TABLE ITAB.
    ITAB_OLD = ITAB.
    ITAB-NEW_DATE = SY-DATUM.
    MODIFY ITAB TRANPORTING NEW_DATE WHERE KEY_FIELD = 'DS'.
    Deletion part.
    DELETE ZTABLE FROM TABLE ITAB_OLD.
    Insertion part
    INSERT ZTABLE FROM TABLE ITAB.
    Thanks,
    Naren

  • Help for inserting/updating new record

    hi,
    i am trying to insert new data in account record in CRM OD from java using (web service v2.0 ) following methods
    AccountInsertInput accountinsert=new AccountInsertInput();
    accountinsert.setListOfAccount(accountDataList);
    Here accountDataList is object of ListOfAccountData.......i want to know how can i insert data in accountDataList that is passed as argument....what i think is that i can create object of AccountData and set required values then convert this to ListOfAccountData(which i am not sure if possible)....pls help
    there is one more problem while updating i am getting ...."No user key can be used for the Integration Component instance 'Account'."....however i have given the combination of user keys....i don't have accountid so i have just given id .....pls help

    Hi,
    there is one more problem while updating i am getting ...."No user key can be used for the Integration Component instance 'Account'."....however i have given the combination of user keys....i don't have accountid so i have just given id .....pls helpPlease ensure that a record exists in CRM On Demand corresponding to the user key values you are providing. This error indicates that no record can be found matching the specified user key.
    Thanks,
    Sean

  • Update New Records is taking much time to complete. How to reduce

    Hi,
    Iam having a Table with 200 Clumns and trying to Update 5 columns and the table has 5lakh Records. It is taking very much time 2hours to complete. Pls let me know why is this taking time how to reduce....
    In my ssis Package iam using
    Oracle Source
    Look up
    Oledb Command for the Update.
    Please help ism stuck?

    I have somthing like this..
    Update table
    Set column1 =@column1, column2=@column2,column3=@column3,column4=@column4,column5=@column5
    where column1=@column1
    in this case i need to add a index on column1 right? Pls llet me know
    Yes, an index in column1 (preferably clustered) would avoid the table scan for each update. The ELT the staging table alternative Jim suggested will likely perform better than individual updates for a large process like this.
    Dan Guzman, SQL Server MVP, http://www.dbdelta.com

  • How to update new records in existing Xcelsius DashBoard

    Hi GUrus,
    I have a question about Xcelsius. I was reading some document and it has mentioned that once we have imported any excel file, it gets stored in Xcelsius and does not communicate with the excel file. IN that case when the record changes how does that gets updated inDashboard. e.g. we have a dashboard which shows sales for all regions for first qtr. If we want to see sales for next qtr do we need to import the file again?
    Can anyone please clarify?
    Regards
    Ray

    Hi,
    The Data connectivity here should be an XML or Qaaws or liveOffice where these 3 data connections has the capabality of Getting data (Upto the minute ) without any manual intervention...
    Try with XML first then you can look forward to Qaaws , Live office...
    Anitivia is a tooll wich is used to connect to Xcelsius and BO.....

  • Any BAPI/Function Module for adding new record with dates in PA0027

    Hi all,
    I am tryig to find is there any BAPI/Function module for updating new record with Start Date and End date for specified Personal Number in PA0027 Table.
    In PA0027 table i will be passing start date and end date for selected personal number, it needs to add new record with this details in the table checking the condition that this start date and end dates should not be between any of of start date and end dates for the specified personal number.
    thanks for ur time.
    Murali

    Hi Raj/Suresh thanks for ur answers.
    but i am having a problem,i gave this values.
    INFTY               -
                0027
    NUMBER              -
                00000010
    SUBTYPE             -
                010
    OBJECTID
    LOCKINDICATOR
    VALIDITYEND         -
                03/12/2006
    VALIDITYBEGIN       -
                03/01/2006
    RECORDNUMBER        -
                000
    RECORD              -
                P0027
    OPERATION           -
                CHK
    TCLAS               -
                A
    DIALOG_MODE         -
                0
    NOCOMMIT            -
                Y
    VIEW_IDENTIFIER
    SECONDARY_RECORD
    i am getting short dump saying that
    The source field is too short.
    The current program, "SAPLHRMM", tried to assign a field to a field symbo
    However, the field is shorter than the type of the field symbol, which
    is not allowed.
    The statement in question is in the form ASSIGN f TO <fs> CASTING or
    ASSIGN f TO <fs> with a field symbol that was created using the
    STRUCTURE addition.
    I tried  operation - Chage,Create (same thing for all inputs)
    is this correct funtion moduel for my requirment?
    what ever i am passing the start and end dates this should check in the table records with this personal number and if this start date and end dates are not between of any start and end dates then it should add new record with this dates.
    Thanks for ur time.
    Murali.

  • How to undo update of checkbox after triggering when-new-record-instance

    Hi,
    I am using eBusiness Forms Personalization in 11.5.10 to alter the Receipts form in Purchasing. I want to prevent users checking the rcv_transaction checkbox if the destination is "Multiple" and, instead, click the "+" sign to explode the multiple record into it's many component records.
    I can do this by invoking the when-new-record-instance trigger to make the "multiple" record fields unalterable and issue a warning message when the user selects such records. However, my problem is that - if the user clicks the checkbox as the first field in a "multiple" record, then this updates the checkbox to "Yes" BEFORE the trigger fires, which then locks the record for update.
    What I need is a solution that either sets the checkbox to unalterable for "multiple" records BEFORE the user clicks into such records, OR a method of undoing the update of the checkbox after the record has been selected (I cannot do this by simply setting it to "No" by the trigger as this is still technically an update and locks the record).
    Cheers
    Graham

    Hi Navnit,
    Yes you are right, but it can work even we not plase quotation mark in it. But Yes I forget to place semi colon so now it is
    IF :System.Cursor_Record = 1 THEN
       :Block.Col1 := '02:00';
    ElsIF :System.Cursor_Record = 2 THEN
       :Block.Col1 := '07:00';
       ------and so on
    END IF;Danish

  • (Administration - Marketing - Import), you can set a parameter value "Import mode" for what to do in case of duplication as "update existing records", "Import new records". The final report of this import is presented as a text file that can be viewed in

    Administration - Marketing -> Import, you can set a parameter value "Import mode" for what to do in case of duplication as "update existing records", "Import new records". The final report of this import is presented as a text file that can be viewed in Business Administration - Marketing -> Import -> Exceptions. Whatever the exception, including duplication import occurs during import and recorded in a text file.   What are the fields that determine the duplicity? How I can I can change those?

    You will be returned anything that is in the option's value parameter. What is displayed in the dropdown and what is put in the value attribute do NOT need to be the same, so maybe you should start there.

  • Update old records and new records to ODS.

    Hi Experts,
    Our requirement: Want to know a method to reset the Recordmode field in Start/Update routine.
    We have 3 ODS. as the picture.
    ODS_2
    ODS_3   (look-up)
    ODS_1
    ODS_3 is lookup table in start routine of ODS_2. We load via delta daily from ODS_1 to ODS_2. In that we have code in start routine as follows:
    DATA: it_tab TYPE STANDARD TABLE OF /bic/aods_100 WITH HEADER LINE.
      CLEAR it_tab[].
      SELECT *
          FROM /bic/aods_100
          INTO TABLE it_tab
          FOR ALL ENTRIES IN DATA_PACKAGE
          WHERE /bic/main_io = DATA_PACKAGE-/bic/main_io.
      LOOP AT it_tab
        WHERE /bic/attr2_nav = ''    (null)
        OR /bic/attr2_nav = ' '.
        delete data_package where /bic/attr2_nav  = it_tab-/bic/attr2_nav.
      ENDLOOP.
    if abort is not equal zero, the update process will be canceled
      ABORT = 0.
    For the above code we are deleting the data_package. But we want the same record to come tomorrow as new record into the data_package, so that if the the field /bic/attr2_nav is not null we can update it.
    But our problem is that once we say delete data_package that record is not updating in the next delta load.
    Please help for this issue.

    You can't set the recordmode on a record in any way that will make it get sent again in the next delta load.  In your data mart scenario BI is keeping track of which records have been sent to the target at the request level.  So, once you have run a delta load from ODS_1 to ODS_2 the Data Mart Status of the Request is set.  You can re-send the whole request by resetting the Data Mart Status of the Request, but you can't selectively re-send individual records from an already processed request.
    Instead, I think you need to redesign your model like this:
    Add the lookup characteristic to ODS_1.  Create a self-update from 8ODS_1 --> ODS_1 and in the start routine perform the lookup on ODS_3 and populate that value into ODS_1.  Create a full load InfoPackage from 8ODS_1 --> ODS_1 and on the data selection tab filter for the lookup value = # (blank).  This will populate the lookup characteristic into ODS_1 from ODS_3 when it is found.
    In the start routine from 8ODS_1 --> ODS_2 delete all the records out of the data package where the lookup field is blank.
    So the steps to load would be:
    1) Load ODS_1 from whatever its source is
    2) Run the self-update from 8ODS_1 --> ODS_1
    3) Run the delta from 8ODS_1 --> ODS_2
    Run these every day or however often you perform the load.
    I think that should give you the desired behavior -- that all records from ODS_1 only flow through to ODS_2 when the lookup against ODS_3 is successful, regardless of whether that is true when a record is first loaded into ODS_1 or only becomes true later after ODS_3 is updated.

  • Update (All Mapped Fields) Import Action creates a new record.....

    Hi All,
    I am on MDM 5.5 sp6,and this weird thing happens everytime i run the "update all mapped fields" option in the import manager,it creates a new duplicate field with the updated value record.Is this  a bug in sp6 or I guess i am going wrong somewhere.I want to update a particular field in the qualified table and i am using a import file which has values for qualified field on the main table and the values for the qualified table itself.
    Any Help greatly appreciated
    Thanks

    Hi Aravind,
    I am on MDM 5.5 sp6,and this weird thing happens everytime i run the "update all mapped fields" option in the import manager,it creates a new duplicate field with the updated value record.Is this a bug in sp6 or I guess i am going wrong somewhere.I want to update a particular field in the qualified table and i am using a import file which has values for qualified field on the main table and the values for the qualified table itself.
    MDM should not behave in this way. I thing there is an issue with the Matching Field you have choosen.
    I think you have choosen all the FIeld as the Matching Field ( Tab) while IMporting.
    Hence any change in any value, creates another dupliacte record( which we do not want)
    Please select any Field with unique values ( like the Material ID, Customer ID etc) which will ensure that the particular records are updated with the new Values coming in.
    You will find the new value getting updated for the records which are already present. It will not create a duplicate record
    Hope it helps.
    *Please reward points if helpful
    Thanks and Regards
    Nitin Jain

  • Sql query to Load only new records,or update old records

    Hi,
    I need a query (not stored procedure) to insert only new records otherwise update existing records.
    I tried by creating "Merge statement in SQl", but the sql query is wrong,it is not updating,always inserting records(replicating..1,2,4,8,16,32..).
    below is my sample query,
    Here "FACT_mytbl -FCT" is my fact table.(which need to update if already records found ,otherwise insert as new records).
    *Inside select ---the table   E_tbl1,E_tbl2  is the business logic table ,using this two table only ,"FACT_mytbl" was created  .So the "S" alias will be the source
    table and "FCT" will be target table. based on this we have to insert or update records.   
      ---Query starts-------------------------------------                    
     MERGE INTO [FACT_mytbl]  FCT
     USING  (
           SELECT 
           FCT1.ID
          ,FCT1.PKcol1
          ,FCT1.FKcol1
          ,FCT1.col1
          ,FCT1.col2
         , FCT1.col3     
       FROM  [FACT_mytbl] FCT1 WITH(NOLOCK)        
       LEFT JOIN dbo.E_tbl1 CT WITH(NOLOCK)
    ON CT.PKcol1=FCT1.PKcol1
       LEFT JOIN dbo.E_tbl2 CT1 WITH(NOLOCK)
    ON CT1.PKcol1=FCT1.PKcol1
       ) S  
       ON FCT.PKcol1 = S.PKcol1 
     WHEN MATCHED AND (FCT.PKcol1 ! = S.PKcol1 ) THEN
     UPDATE SET       
           FCT.col1
          ,FCT.col2
          ,FCT.col3     
     WHEN NOT MATCHED THEN 
     INSERT VALUES
           S.ID
          ,S.PKcol1
          ,S.FKcol1
          ,S.col1
          ,S.col2
         , S.col3     
    --query ends----------------
    any suggestions,
    Thanks,
    R.B

    Hi Bhupesh_Rajasekaran,
    According to your description, if you want to insert only new records which does not exist in destination and update existing records which does exist in destination. We usually accomplish these in two statement.
    1.A join statement to update records.
    2.A insert statement for new records.
    Also we can use MERGE in SQL Server to insert, update at the same time. You specify a "Source" record set and a "Target" table, and the join between the two. You then specify the type of data modification that is to occur when the records between the two
    data are matched or are not matched. For more information, there is an similar example about merge in SQL Server, you can review the following article.
    http://www.codeproject.com/Tips/590085/Merge-in-SQL-Server
    Regards,
    Sofiya Li
    Sofiya Li
    TechNet Community Support

  • Settings for update/insert new records

    Hi everybody,
    I'm at the beggining of learning the OWB in order to create a Data Warehouse environment.
    I have successfully created a table in the target schema , which is a match of columns found in 4 tables in the source schema.
    Which settings(steps) are necessary in order to update some records according to the update done in 4 tables in source schema , which have already been inserted in the table in target schema- using the execute pop-up menu command?
    Additionally , how can I insert only the new records to the target schema by using the execute command in pop-up menu ...
    Thanks , a lot
    Simon

    Hi Simon,
    If you have constraints set on your target table, and the operator properties are set to "Match by Constraints = All Constraints", then the process recognizes automatically when to update which fields and when to insert new records.
    If you have no constraints on your target then the operator properties are set to"Match by Constraints = No Constraints", and in this case you should set the Loading properties for each attribute (Field) in the target table.
    Greetings,
    Ilona Tielke

  • Xth data - updated with new records in exit- layout does not show new recor

    Hi ,
    I have updated Xth_data table in an exit function with new set of records. I can in debug mode in the exit function 204 records in Xth_data and after the logic 408 records. But somehow , when the layout comes up , it comes up with only 204 records instead of 408. I have populated all the key fields of xh_data with characteristic value. But still these are missing in the layout. Please let me now if you guys have come across simillar situation.
    204 records are read , 0 of them were changed, 276 generated.
    Thanks
    JC

    Hi,
    Surely that the new record do not match with the selection of your package.
    You should execute the function withj the trace, so you can access the full log.
    Regards

Maybe you are looking for

  • Printing and Preview does not work anymore after 10.9.5 Update

    I discovered today three topics not working anymore correctly without having installed or changed any particular setup (besides standard App Store Updates). I meanwhil repaired permissions but with now success, any hint of anyone to help resolve my i

  • My iPod Touch Is Dead and Won't Charge

    I have a 2nd Generation 16GB iPod Touch.  I have had it for a year and half.  I use it very often. Yesterday, it just all the sudden shut off.  It was low on battery, but it didn't even do it's usual black screen and the loading logo.  It just comple

  • SR830 data storage for rs232

    Hi, I found a LabVIEW code here which can storage data from input signal (e.g.A/I)in SR830 and transfer it by the GPIB. I used function generator to generate a sine wave with frequency:30Hz& Vp-p:100mVolt , conencting to SR830. Clearly ,I got a corre

  • Flash crashes literally 100% of the time, on all browsers

    OS : Windows 7 Flash version: 15.0.0.239 Browsers tried: Firefox 34.0.5, Chrome, IE Every single time (not exaggerating), when I navigate to a site that has flash, it will get very slow, then a popup saying "Shockwave Flash might be busy...". Waiting

  • Open an image in photoshop / MS-picture Managerthrugh JSP/Servlet--Urgernt

    friends, Problem: Developing an web page ...which having an Image . I want to open particluar Image in Adobe Photoshop or MS-picture Manager. ---so that User can Edit picturein Adobe Photoshop or MS-picture Manager. in same Webpage.