Want to copy the data form one table to another.

I have two tables named COMP_TRAINING_T and TRNG_CMTS_COMMENTS.
Now i feel the TRNG_CMTS_COMMENTS is needed so i am moving a column from this table to COMP_TRAINING_T.
I already have some data in both tables. I have add the column in COMP_TRAINING_T and want to update this table as follows
update COMP_TRAINING_T a
SET COMP_TRNG_COMMENTS=
( Select COMP_TRNG_CMTS_COMMENTS from comp_trng_cmts_t b
where a.comp_trng_finance_nbr= b.comp_trng_cmts_finance_nbr and
a.comp_trng_audit_userid=b.comp_trng_cmts_audit_userid and
a.comp_trng_date= b.comp_trng_cmts_date and
a.comp_trng_userid= b.comp_trng_cmts_userid)
but it is updating the rows correctly for the data it found from the COMP_TRNG_CMTS_COMMENTS table but for other rows it is setting it as Null value.
How to rewrite this sql.
Thanks

Hi,
Welcome to the forum!
You're doing an UPDATE statement without a WHERE clause, so every row in the destination table will be updated. If the correlated sib-query doesn't find any matching rows in the source table, there's no error, but NULL is returned, so some rows in the destination table may get set to NULL.
To avoid that, you can use MERGE:
MERGE INTO     comp_training_t     a
USING (
      SELECT     comp_trng_cmts_comments
      ,          comp_trng_cmts_finance_nbr
      ,          comp_trng_cmts_audit_userid
      ,          comp_trng_cmts_date
      ,          comp_trng_cmts_userid
      FROM     comp_trng_cmts_t
      )  b
ON    (          a.comp_trng_finance_nbr      = b.comp_trng_cmts_finance_nbr
      AND     a.comp_trng_audit_userid = b.comp_trng_cmts_audit_userid
      AND     a.comp_trng_date      = b.comp_trng_cmts_date
      AND     a.comp_trng_userid      = b.comp_trng_cmts_userid
WHEN MATCHED THEN UPDATE
SET   a.comp_trng_comments     = b.comp_trng_cmts_comments
;MERGE tests (using the ON conditions) whether or not ther is a match between the destination table and the source sub-query.
If there is a match, it can do an UPDATE.
If there is no match, it can do an INSERT. In this case, we don't want to insert any new rows, so we just omit the WHEN NOT MATCHED clause.
Notice that the USING sub-query returns all the columns from the source table that play any role in this job.
The ON clause contains all the correlation conditions that were in your original statement.
The alternatives, using UPDATE are:
(a) Update all rows, but use NVL to set values to themselves if the sub-query returns NULL
(b) Add a WHERE clause that repeats the correlated sub-query.
Neither is efficient, and (b) is a maintenance problem, too: if tyou ever change the conditions, you have to make the same change in two places.
By the way, this site compresses whitespace by default.
if you need to post formatted code or output, then type these 6 characters:
(small letters only, inside curly brackets) before and after sections of formatted text, to preserve spacing.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Similar Messages

  • Want to copy/append data in one table to another

    Hi,
    I have two similar tables Alo_table and Alo_table_test with different indexes, partitions etc.
    Alo_table has some data. I want to copy/append this data in to Alo_table_test for further testing. How to copy/append data without changing the other settings from Alo_table to Alo_table_test?
    Thanks in advance,
    S

    May be you are Looking for MERGE statement
    It will Insert New Record if not Found to your Destinamtion table or Update if Record Found
    MERGE INTO bonuses B
    USING (
      SELECT employee_id, salary
      FROM employee
      WHERE dept_no =20) E
    ON (B.employee_id = E.employee_id)
    WHEN MATCHED THEN
      UPDATE SET B.bonus = E.salary * 0.1
    WHEN NOT MATCHED THEN
      INSERT (B.employee_id, B.bonus)
      VALUES (E.employee_id, E.salary * 0.05);

  • How to copy the data from one database to another database without DB link

    Good Day,
    I want to copy the data from one database to another database with out DB link but the structure is same in both.
    Thanks
    Nihar

    You could use SQL*Plus' COPY command
    http://technology.amis.nl/blog/432/little-gold-nugget-sqlplus-copy-command
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14357/apb.htm#sthref3702
    Edited by: Alex Nuijten on Sep 16, 2009 8:13 AM

  • How to copy the data of one node to another of the same context

    hi experts,
          i need to copy the data of one node to the other node of the same context.
    the source node is a model node ( i.e comming from <b>RFC</b> ) and the destination node is a value node which i have creted.
    what i have done is.
    i have read the source node using wizard
    do.
    elem_t_p0591 = node_t_p0591->get_element(
        index = sy-index ).
        IF ( elem_t_p0591 IS INITIAL ).
          EXIT.
        ENDIF.
    elem_t_p0591->get_static_attributes(
          IMPORTING
            static_attributes = stru_t_p0591 ).
    IF stru_t_p0591 IS NOT INITIAL.
          wa_p0591 = stru_t_p0591.
          APPEND wa_p0591 TO itab_p0591.
        ENDIF.
      ENDDO.
    and then i am trying to read the destination node so the tha data i have got by above method can be binded to the destination node.
    but when i am trying to get the child node it is giving me a dump saying that
    <b>'Access via 'NULL' object reference not possible' </b> i understand this because when i debug my value node is becoming <b>initial</b>, and when i am trying to access the destination node using this <b>initial</b> node it will give me a dump,
    but what is the work aroud for this.
    Plz help.
    Regards,
    Santosh.

    Hi Santosh,
                   I tried replicating your behaviour in my system. This is what my context structure looks like:
    Node_Test (c-> 0:n)
      Name(attribute)
      Node_Test2 (c-> 0:1)
         Name2(attribute)
    Now when i try to access Node_Test2 then it returns me (initial) i.e. no reference and i believe the reason is that my parent node, Node_Test, is of type table( because of the cardinality) so I am expected to perform an operation on my sub node, Node_Test2, based on the node i have selected, or have specified via index .. 1 is taken by default, in Node_Test.. which in WDDOINIT is initial as i havent got access to my view yet.. so instead what you can do is bind data to your parent node, relevant data ofcourse, and then bind the recieved data to your child node i.e. Node3.
    I am pasting the code here for your reference :
    method WDDOINIT .
           DATA:
             node_test                           TYPE REF TO if_wd_context_node,
             elem_test                           TYPE REF TO if_wd_context_element,
             stru_test                           TYPE wd_this->element_test ,
             lt_table   LIKE TABLE OF stru_test,
             item_test_1                         LIKE stru_test-test_1.
         navigate from <CONTEXT> to <TEST> via lead selection
           node_test = wd_context->get_child_node( name = wd_this->wdctx_test ).
         @TODO handle not set lead selection
           IF ( node_test IS INITIAL ).
           ENDIF.
         get element via lead selection
           elem_test = node_test->get_element(  ).
         @TODO handle not set lead selection
           IF ( elem_test IS INITIAL ).
           ENDIF.
    stru_test-test_1 = 'Anoop'.
    APPEND stru_test to lt_table.
    stru_test-test_1 = 'Avi'.
    APPEND stru_test to lt_table.
    stru_test-test_1 = 'Sid'.
    APPEND stru_test to lt_table.
    CALL METHOD node_test->bind_table
      EXPORTING
        new_items            = lt_table
       set_initial_elements = ABAP_TRUE
       index                =
          DATA:
            node_t2                             TYPE REF TO if_wd_context_node,
            elem_t2                             TYPE REF TO if_wd_context_element,
            stru_t2                             TYPE wd_this->element_t2 ,
            item_t2_1                           LIKE stru_t2-t2_1.
        navigate from <CONTEXT> to <TEST> via lead selection
         node_test = wd_context->get_child_node( name = wd_this->wdctx_test ).
        @TODO handle not set lead selection
          IF ( node_test IS INITIAL ).
          ENDIF.
    <b>*     navigate from <TEST> to <T2> via lead selection
          node_t2 = node_test->get_child_node( name = wd_this->wdctx_t2 ).</b>
    <b>*     alternative navigation via index
         Node_T2 = Node_Test->get_Child_Node(
           Name = `T2` Index = 1 ).</b>
        @TODO handle non existant child
        if ( Node_T2 is initial ).
        endif.
        get element via lead selection
          elem_t2 = node_t2->get_element(  ).
        get single attribute
          elem_t2->get_attribute(
            EXPORTING
              name =  `T2_1`
            IMPORTING
              value = item_t2_1 ).
    endmethod.
    I hope this helps.
    Regards,
    Anoop

  • Copy the data from one column to another column using @

    I have two columns here - A and B.
    Column A has a complicated formula that will generate results. I wanted the results in Column A to be reflected in Column B without pasting the A's formula in B. This will save me the trouble of editing formulas in more than 1 column if there is a need.
    I saw somewhere that you can use "@" in column B but I have no idea how to use it.
    Assumingly column A is the first column. I tried to insert '@1' in B's formula and change B's column properties' Data Format as "Treat Text as HTML". It does not work.
    Please advise how I can do that.

    So is there any way to copy the data in Column A into Column B without putting the same formula? something like in Excel where we put "=C1". Its not possible in BI as it comes in excel.....The only way is to create a duplicate column in RPD or Answers screen and incorporate the formula and giving different name to it.
    whats the problem if you duplicate the column with same formula?....Ok still if you dont want to see identical just write some pseudo logic say
    Duplicated column f(x) case when 1=0 then column_name else formula end.....so it appears different to see but it outputs same.
    UPDATED POST
    Dont create in RPD,you can create a dummy column in that report request and change the f(x) to the above case i mentioned by taking the column from columns button in edit formula screen so when ever you edit the actual column formula that would reflect in the dummy column also as it is replicating from original one.Try and see
    hope helps you.
    Cheers,
    KK
    Edited by: Kranthi.K on Jun 2, 2011 1:26 AM

  • How do the copy the Recording form one client to another client.

    Hi all
    I have one scenario like
    We need to process the sales documents which are not process to output(means send the document to printer) .
    For that I have to write a BDC program,
    In that program we  need to list out the all the documents which are not process .
    Then we need to do the Recording for VA02.
    NAVIGATION IS LIKE : va02 --> enter the doc No --> go the Extract(main menu) --> output --> Header --> Edit --> select the output type -->Save --> go the Sales Document(in main menu option) --> issue output --> print.
    But what my quarry is we have  to do Record that T-Code (VA02)  client 040 but we don’t have any test data (any entries),
    We have another client 093, in this client we don’t have authorization properly, means I able to Record but I am unable to create the program after recording why becace we don't ahve authorization for SE38.
    Please tell me is there any possible Export the Record form one  client and Import to another client.

    Hi Amjad,
    Yes we can transfer from one client to another client.
    to copy client from 901 to 903. if you have created a recording in client 901, go to transactions SHDB, double click on the specific recording, it will open the recording. there got to menu path: recording->export. export to a text file.
    in client 903 create a sample recording. open the recording in change mode, delete all lines. then go to menu path Recording->import, import the text file.
    it will works fine.
    Regards
    Krishnendu

  • Insert the values form one table to another

    Hi.,
    I am using jdev11.1.5
    I had created a reaadonly VO using the follwing querry
    select distinct fp_bu,fp_year,fp_period, decode(gdh_status,'R','Yes','No') distribution,decode (aj_status ,'N','Yes','No') Recursion,
    decode(RSUPHD_STATUS,'P','Yes','No') Supplier,decode(RCDOC_STATUS,'P','Yes','No') Customer
    from gl_dist_hd,fin_periods,appl_journals,rec_suplr_doc_hd,rec_cust_doc_hd
    where fp_bu = gdh_bu(+) and
    gdh_bu = aj_bu(+) and
    aj_bu = RSUPHD_BU(+) and
    RSUPHD_BU = RCDOC_BU(+) and
    fp_year = gdh_year(+) and
    gdh_year = aj_year(+) and
    aj_year = RSUPHD_DOC_YEAR(+) and
    RSUPHD_DOC_YEAR = RCDOC_DOC_YEAR(+) and
    fp_period = gdh_period(+) and
    gdh_period = aj_period(+) and
    aj_period = RSUPHD_DOC_PERIOD(+) and
    RSUPHD_DOC_PERIOD = RCDOC_DOC_PERIOD(+)
    ORDER BY fp_period asci had created a button [post]
    when the user clicks the button it must insert the values of table CursorC1 into GlJrnlHd
    i had tried a querry in AMImpl
            ViewObjectImpl vo = this.getGlJrnlHd1();
            Row newRow = vo.createRow();
            ViewObjectImpl c1 = this.getCursorC1_1();
            Row cr1 = c1.getCurrentRow();
               newRow.setAttribute("GjhBu", cr1.getAttribute("GrhBu"));
           newRow.setAttribute("GjhPlant", cr1.getAttribute("GrhPlant"));
          newRow.setAttribute("GjhJrnlType", cr1.getAttribute("GrvlJrnlType"));
           newRow.setAttribute("GjhJrnlNo", cr1.getAttribute("GrvlJrnlNo"));
           newRow.setAttribute("GjhJrnlSfx", cr1.getAttribute("GrhJrnlSfx"));
           newRow.setAttribute("GjhJrnlDate", "Null");
           newRow.setAttribute("GjhYear", cr1.getAttribute("GrvlYear"));
           newRow.setAttribute("GjhPeriod", cr1.getAttribute("GrvlPeriod"));
           newRow.setAttribute("GjhDesc", cr1.getAttribute("GrhDesc"));
           newRow.setAttribute("GjhAppl", "GLM");
           newRow.setAttribute("GjhReversal", "N");
           newRow.setAttribute("GjhStatus","N");
           newRow.setAttribute("GjhCreBy", "NULL");
           newRow.setAttribute("GjhCreDate", "NULL");
           newRow.setAttribute("GjhUpdBy", "NULL");
           newRow.setAttribute("GjhUpdDate", "NULL");
           this.getTransaction().commit();i am getting null pointer exception at this line
    newRow.setAttribute("GjhBu", cr1.getAttribute("GrhBu"));could anyone please help me to resolve this error

    Hi,
    give a NPE check
    ViewObjectImpl vo = this.getGlJrnlHd1();
            Row newRow = vo.createRow();
            ViewObjectImpl c1 = this.getCursorC1_1();
            Row cr1 = c1.getCurrentRow();
            if (cr1 != null){
            newRow.setAttribute("GjhBu", cr1.getAttribute("GrhBu"));
           newRow.setAttribute("GjhPlant", cr1.getAttribute("GrhPlant"));
          newRow.setAttribute("GjhJrnlType", cr1.getAttribute("GrvlJrnlType"));
           newRow.setAttribute("GjhJrnlNo", cr1.getAttribute("GrvlJrnlNo"));
           newRow.setAttribute("GjhJrnlSfx", cr1.getAttribute("GrhJrnlSfx"));
           newRow.setAttribute("GjhJrnlDate", "Null");
           newRow.setAttribute("GjhYear", cr1.getAttribute("GrvlYear"));
           newRow.setAttribute("GjhPeriod", cr1.getAttribute("GrvlPeriod"));
           newRow.setAttribute("GjhDesc", cr1.getAttribute("GrhDesc"));
           newRow.setAttribute("GjhAppl", "GLM");
           newRow.setAttribute("GjhReversal", "N");
           newRow.setAttribute("GjhStatus","N");
           newRow.setAttribute("GjhCreBy", "NULL");
           newRow.setAttribute("GjhCreDate", "NULL");
           newRow.setAttribute("GjhUpdBy", "NULL");
           newRow.setAttribute("GjhUpdDate", "NULL");
           this.getTransaction().commit();
    }

  • Copying data from one table to another table thru java

    Hi
    I have to copy data from table emp in Database A to table emp in Database B. My input would be table name and number of rows to be fetched. these rows i need to insert in table B.
    The problem over here is I won't be having any info. of table emp i.e the number of columns it has and their type.
    So is their any way i can copy the data from one table to other without having the info abt the number of cols and their type.
    TIA

    Cross post - http://forum.java.sun.com/thread.jspa?threadID=5169293&messageID=9649839#9649839

  • Flowing data from one Table to another

    I am new to Numbers and I am having a hard time figuring out how to flow a sum from one table into another table. Is this possible? Please help.
    Thanks
    E

    lassiegirl wrote:
    I am new to Numbers and I am having a hard time figuring out how to flow a sum from one table into another table. Is this possible? Please help.
    Hi lassiegirl,
    Welcome to Apple Discussions and the Numbers '09 forum.
    Apple provides two excellent resources that I recommend be downloaded by all Numbers users, the Numbers '09 User Guide and the iWork Formulas and Functions User Guide. You'll find linke for both of them in the Help menu in Numbers.
    The first will give you an overview of Numbers and how it works—spend some time with the preface and the first chapter, browse the rest on a need to know basis when you're doing something new. The second is a reference, useful when you're trying to write a formula.
    To your question...
    You can copy the sum from one table to another.
    For the example formula beow, both Table 1 and Table 2 have one header row and one footer row, and a total of 21 rows each.
    If the SUM on Table 1 is in cell C21, and you want to include it in the SUM of column C in Table 2, you could transfer the sum to C1 in the header row of Table 2 with:
    C1:  =Table 1::C21
    In C21 of Table 2 (a Footer row), use any of these formulas:
    =SUM(C)+C1
    =SUM(Table 1::C)+SUM(C)
    =SUM(Table 1 :: C,C)
    The first calculates the sum of the cells in column C (of its own table—Table 2) and adds the value in C1, the total transferred from Table 1.
    The second returns the same result by calculating the sums of the two columns separately, then adding those sums.
    The third takes the single arguments of the two SUM statements in the second, and lists them as multiple arguments in a single SUM statement.
    Regards,
    Barry

  • Append data from one table to another.

    Hi,
    I want to insert/append some or all the data from one table to another table.
    For eg: Data from table table1 to be appended to table2 with the same constraints, indexes etc. The columns are same for both the tables.
    I am using 10g version 2.
    Please specify which method would be good for this process.
    Thanks
    Jafar

    INSERT INTO TABLE1 SELECT * FROM TABLE2;The above command would insert data into table2 and it also contain the old data.Is that right,
    Thanks
    Jafar

  • I want to get the data of a table inside the Form but it is not passed

    I want to get the data of a table inside the Form but it is not passed to the form by tables parameters.
    How can I do this.
    Regards

    If there is a problem with defining it globaly, you can define a field symbol globably and point to it. For example.  It would probably be better to define your table globably.
    report zrich_0003 .
    field-symbols: <imarc> type marc_upl_tt.
    start-of-selection.
      perform get_data.
    *       FORM get_data                                                 *
    form get_data.
      data: imarc type table of marc with header line.
      select * from marc into table imarc up to 10 rows.
      assign imarc[] to <imarc>.
      perform write_data.
    endform.
    *       FORM write_data                                               *
    form write_data.
      data: xmarc type marc.
      loop at <imarc> into xmarc.
        write: / xmarc-matnr, xmarc-werks.
      endloop.
    endform.
    Regards,
    Rich Heilman

  • How to copy data from one table to another (in other database)

    Hi. I would like to copy all rows from one table to another (and not use BC4J). Tables can be in various databases. I have already 2 connections and I am able to browse source table using
    ResultSet rset = stmt.executeQuery("select ...");
    But I would not like to create special insert statement for every row . There will be problems with date formats etc and it will be slow. Can I use retrieved ResultSet somehow ? Maybe with method insertRow, but how, if ResultSet is based on select statement and want to insert into target table? Please point me in the right direction. Thanks.

    No tools please, it must be common solution. We suceeded in converting our BC4J aplication to PostgreSQL, the MSSQL will be next. So we want to write simple aplication, which could transfer data from our tables between these 3 servers.

  • T code to Copy Data from one table to another table

    Hi,
    I want copy all data of one table to its copy table. Anyone knows transaction code to copy data from one table to another table.
    Regards,
    Jigar Thakkar.

    Hi
    Create a small program.
    Extract data from T1 - database table and put it in one internal table - itab1.
    loop the itab1 data .............
        insert itab1 into tab2.   (tab2 - second database table)
    endloop.
    try this....
    hope it works....

  • Copy data from one Table to another Table

    How can I copy data from one Oracle Table to another Oracle Table on a different server? Question 2: How can I clear all of the data in one Table with a single SQL script?
    Thanks...

    Question 1:
    I assume you have the privileges. If you don't, ask the DBA to give them to you. Then
    1. Login to database_source (It could be either the source or the target. Let's assume it's the source.)
    2. Create a database link to database_target: CREATE DATABASE LINK link_to_database_target CONNECT TO myuserid IDENTIFIED BY mypassword USING 'database_target'; Note the single quotes.
    3. Copy the table data: INSERT INTO targetowner.mytable@link_to_database_target SELECT * FROM sourceowner.mytable; COMMIT;
    Question 2:
    You have two options, but you may not have privileges for both.
    Option 1:
    DELETE FROM tableowner.tablename; COMMIT;
    Advantage: Since this is a DML (Data Manipulation Language) statement, you have to commit the transaction. Also, the data will be gone but the table size is NOT changed, so it's ready for accepting replacement data. DML statements can simply be executed not only from SQL scripts, but from PL/SQL scripts as well.
    Disadvantage: Slow, because all record deletion is logged, so you can recover from it by issuing a ROLLBACK; instead of the COMMIT; above. The table size is NOT changed, so if you are short of disk space or tablespace space, you have not resolved the issue.
    Option 2:
    TRUNCATE TABLE tableowner.tablename;
    Advantage: Since this is a DDL (Data Definition Language) command, you do NOT have to commit the transaction. (DDL commands automatically commit both before and after their execution.) The table size will be changed back to the initial extent size which is the minimum size a table can have and can only be set when the table is created. If it needs to be changed, the table has to be dropped and recreated with a different initial extent size. The statement execution of this command is not logged, therefore it's much faster then the DELETE.
    Disadvantage: No rollback. Being a DDL, this command cannot be executed straight from PL/SQL. If you need to issue this within PL/SQL, you will have to use dynamic SQL.

  • !0.5.8 How do I copy the 'system' form one internal Hard drive to an other (BY CD Packed up) Thank you

    !0.5.8 How do I copy the 'system' form one internal Hard drive to an other (BY CD Packed up)  I have tried but it will no show 'live' system folder - do and how can I bless it ? Thank you

    Carbon Copy Cloner will allow you to de-select directory trees, so you could use it to copy over everything EXCEPT the /Users directory tree.
    Mac OS X is NOT just the System Folder.  If you do not copy over the rest of Mac OS X, it will not boot.  So better to exclude Users and take everything else, then it is to try and pick and choose.
    The other approach is to install a New Mac OS X, and then copy over the stuff you want from the home folder(s) and reinstall any apps you want.

Maybe you are looking for