Copying and updating Data  from a table to new table using Merge command

Hi ,
Can anyone please tell me how to do this?
I have a table : EMP(empno(pk),ename,sal,dept) another table is EMP_CLASS(empno(pk),ename)
I want to insert corresponding rows from emp to emp_class table if that row does'nt exist in emp_class
otherwise it will update corrsponding info in emp_class table as well as delete from emp_class according to emp delete operation.
Thanks ,
Deekay.
Edited by: Deekay on Aug 12, 2010 10:59 PM

Hi Vishu,
This is really helpful, but I want little modification like it will check for deptno in emp and insert in class field if dept is 10 then 1 ,20 ,2 like wise. I have changed emp_class structure .Please find my updated code eaccording to that ,but I am getting error.
MERGE
INTO emp_class
USING emp
ON  (emp.empno = emp_class.empno)
WHEN MATCHED
THEN
UPDATE
SET emp_class.ename = emp.calss_name,
    emp_class.deptno = emp.deptno,
    emp_class.class=select decode(deptno,10,1,20,2,30,3,40,4)from emp
DELETE
WHERE emp_class.empno = emp.empno
WHEN NOT MATCHED
THEN
INSERT (emp_class.empno,emp_class.name,emp_class.deptno,emp_class.class)
VALUES (emp.empno,emp.name,emp.sal,emp.deptno,decode(deptno,10,1,20,2,30,3,40,4)emp.class);
    Please help me to fix this.
this is the error:
MERGE
INTO emp_class
USING emp
ON (emp.empno = emp_class.empno)
WHEN MATCHED
THEN
UPDATE
SET emp_class.ename = emp.calss_name,
emp_class.deptno = emp.deptno,
emp_class.class=select decode(deptno,10,1,20,2,30,3,40,4)from emp
DELETE
WHERE emp_class.empno = emp.empno
WHEN NOT MATCHED
THEN
INSERT (emp_class.empno,emp_class.name,emp_class.deptno,emp_class.class)
VALUES (emp.empno,emp.name,emp.sal,emp.deptno,decode(deptno,10,1,20,2,30,3,40,4)emp.class);

Similar Messages

  • Creating a external content type for Read and Update data from two tables in sqlserver using sharepoint designer

    Hi
    how to create a external content type for  Read and Update data from two tables in  sqlserver using sharepoint designer 2010
    i created a bcs service using centraladministration site
    i have two tables in sqlserver
    1)Employee
    -empno
    -firstname
    -lastname
    2)EmpDepartment
    -empno
    -deptno
    -location
    i want to just create a list to display employee details from two tables
    empid firstname deptno location
    and same time update  in two tables
    adil

    When I try to create an external content type based on a view (AdventureWorks2012.vSalesPerson) - I can display the data in an external list.  When I attempt to edit it, I get an error:
    External List fails when attached to a SQL view        
    Sorry, something went wrong
    Failed to update a list item for this external list based on the Entity (External Content Type) 'SalesForce' in EntityNamespace 'http://xxxxxxxx'. Details: The query against the database caused an error.
    I can edit the view in SQL Manager, so it seems strange that it fails.
    Any advice would be greatly GREATLY appreciated. 
    Thanks,
    Randy

  • Retreiving data from 2 tables using a sender JDBC Channel

    Hi all,
    We got anew requirement where we have to select data from 2 tables and update fields in 2 tables at the sametime.
    I have a few queries regarding this.
    Can we retrieve data from 2 tables using select query in sender JDBC channel?
    If yes, how we can achieve this?
    Can we use inner/outer joins in the select query?
    Can we update field of 2 tables using the Update query in Sender JDBC channel?
    Your help is greatly rewarded.
    With Regards
    Sudha.

    Hi,
    Even i have the same requirement where data has to be read from 2 tables and later update the falg once done .
    SELECT query :
    SELECT t1.KUNNR,t1.SETT_KEY,t1.QUART_START,t1.QUART_END,t2.PAY_METH,t2.MAT_NDC,t2.AMOUNT   FROM TSAP_REBATE_MEDI t1  INNER JOIN  TSAP_REBATE_LINE t2  ON  t1.KUNNR=t2.KUNNR AND t1.SETT_KEY=t2.SETT_KEY  WHERE  t1.PROCESSING_STATUS = 'N' AND t2.PROCESSING_STATUS = 'N'
    This is working fine.
    Can somebody help me with update query with this. where flag PROCESSING_STATUS has to be updated with 'P'.
    I tried a lot but couldnt get the answer
    Br,
    Manoj

  • How to select data from a table using a date field in the where condition?

    How to select data from a table using a date field in the where condition?
    For eg:
    data itab like equk occurs 0 with header line.
    select * from equk into table itab where werks = 'C001'
                                                      and bdatu = '31129999'.
    thanks.

    Hi Ramesh,
    Specify the date format as YYYYMMDD in where condition.
    Dates are internally stored in SAP as YYYYMMDD only.
    Change your date format in WHERE condition as follows.
    data itab like equk occurs 0 with header line.
    select * from equk into table itab where werks = 'C001'
    and bdatu = <b>'99991231'.</b>
    I doubt check your data base table EQUK on this date for the existince of data.
    Otherwise, just change the conidition on BDATU like below to see all entries prior to this date.
    data itab like equk occurs 0 with header line.
    select * from equk into table itab where werks = 'C001'
    and <b> bdatu <= '99991231'.</b>
    Thanks,
    Vinay
    Thanks,
    Vinay

  • I would like to copy and paste photos from iphoto to a cd for use

    I would like to copy and paste photos from iphoto to a cd for use.  How can I do this so it can be used for further work in other computers without iphoto?
    Steve

    You can't do that.
    Export the Photos (File -> Export) to a folder on the desktop. Then burn that to the CD using the Finder's Burn Disk command.
    Regards
    TD

  • Read data from ODS table using value mapping

    hi all;
    can anyone help on how to read data from ODS table using value mapping

    Mudit,
    Take a look at this blog,
    <a href="/people/siva.maranani/blog/2005/08/23/lookup146s-in-xi-made-simpler">DB Lookup in Mapping</a>
    Regards,
    Bhavesh

  • Help with writing and retrieving data from a table field with type "LCHR"

    Hi Experts,
    I need help with writing and reading data from a database table field which has a type of "LCHR". I have given an example of the original code but don't know what to change it to in order to fix it and still read in the original data that's stored in the LCHR field.
    Basically we have two Function modules, one that saves list data to a database table and one that reads in this data. Both Function modules have an identicle table which has an array of fields from type INT4, CHAR, and type P. The INT4 field is the first one.
    Incidentally this worked in the 4.7 non-unicode system but is now dumping in the new ECC6 Unicode system.
    Thanks in advance,
    C
    SAVING THE LIST DATA TO DB
    DATA: L_WA(800).
    LOOP AT T_TAB into L_WA.
    ZDBTAB-DATALEN = STRLEN( L_WA ).
    MOVE: L_WA to ZDBTAB-RAWDATA.
    ZDBTAB-LINENUM = SY-TABIX.
    INSERT ZDBTAB.
    READING THE DATA FROM DB
    DATA: BEGIN OF T_DATA,
                 SEQNR type ZDBTAB-LINENUM,
                 DATA type ZDBTAB-RAWDATA,
               END OF T_TAB.
    Select the data.
    SELECT linenum rawdata from ZDBTAB into table T_DATA
         WHERE repid = w_repname
         AND rundate = w_rundate
         ORDER BY linenum.
    Populate calling Internal Table.
    LOOP AT T-DATA.
    APPEND T_DATA to T_TAB.
    ENDLOOP.

    Hi Anuj,
    The unicode flag is active.
    When I run our report and then to try and save the list data a dump is happening at the following point
    LOOP AT T_TAB into L_WA.
    As I say, T_TAB consists of different fields and field types whereas L_WA is CHAR 800. The dump mentions UC_OBJECTS_NOT_CONVERTIBLE
    When I try to load a saved list the dump is happening at the following point
    APPEND T_DATA-RAWDATA to T_TAB.
    T_DATA-RAWDATA is type LCHR and T_TAB consists of different fields and field types.
    In both examples the dumps mention UC_OBJECTS_NOT_CONVERTIBLE
    Regards
    C

  • Hey guys how to fetch data from db table using subroutine

    hi guys,
                   I am fetching data from db table "mcha". now in the follwing code i get it in "HSDAT1_DATE."
                   now when i read out_tab with key "HSDAT1". it wont come in out_tab-value.plz tell me what is wrong whether some key condition in out_tab or any thing else.
    and what should i write in changing && in script.
    thanks in advance
    FORM DATE_MGF TABLES IN_TAB STRUCTURE ITCSY
                         OUT_TAB STRUCTURE ITCSY.
    tables :MCHA ,QALS.
      DATA : WERKS1 LIKE QALS-WERK.
      DATA : HSDAT1 LIKE MCHA-HSDAT.
      DATA : DATE(2),
             MONTH(2),
             YEAR(4).
    DATA : HSDAT1_DATE(10).
      READ TABLE IN_TAB WITH KEY 'QALS-WERK'.
      LOOP AT IN_TAB.
        IF SY-TABIX EQ 1.
          WERKS1 = IN_TAB-VALUE.
          IF WERKS1 NE SPACE.
            EXIT.
          ENDIF.
        ENDIF.
      ENDLOOP.
      SELECT SINGLE HSDAT INTO HSDAT1
                          FROM MCHA
                                    WHERE  WERKS = WERKS1.
      DATE = HSDAT1+6(2).
      MONTH = HSDAT1+4(2).
      YEAR = HSDAT1+0(4).
      CONCATENATE DATE '.' MONTH '.' YEAR INTO HSDAT1_DATE.
      READ TABLE OUT_TAB WITH KEY 'HSDAT1' .
      IF SY-SUBRC = 0.
        OUT_TAB-VALUE = HSDAT1.
        MODIFY OUT_TAB INDEX SY-TABIX.
      ENDIF.

    Hi,
    Let me understanf clearly what you want.
    initally mine out_tab is blank
    According to you, your table out_tab is blank. And you need to add out_tab-value = HSDAT1_date.
    READ TABLE OUT_TAB WITH KEY 'HSDAT1' .
      IF SY-SUBRC = 0.
        OUT_TAB-VALUE = HSDAT1.
        MODIFY OUT_TAB INDEX SY-TABIX.
      ENDIF.
    So, if your table is blank, then read statement will fail.
    Please let me know if your table out_tab in blank when you are reading the table and if this table contains any field called HSDAT.
    Basically i would like to know your internal table out_tab declaration.
    Thanks,
    Archana

  • Extracting data from multiple tables using DB connect

    Hi,
       I am having different tables which are  having the same structure in oracle database but  there names are different.Now i have only one datasource at BI side.This datasource shld extract data from the  tables dynamically.How can i do it using DB Connect .
    Thnxs

    ahh I see - problem as you said then is if you then take on a new location!
    I would then put into the source system a table identifier and create a view across all the tables
    Then dbconnect from the view and use the selection parameter of table parameter if you wanted one infopackage per "location"
    If you do need to have a new table in the source then just expand the view and create a new ipak
    hence NO bw changes required that need a dev-q-p transport - just the ipak in prod and it;s the source systems problem to add the extra table to the view

  • Issue while insert and update data to DB tables

    Hello all,
    i am having an issue while insert the data to DB table.
    my scenario is DB1 to DB2. i had a sender channel with select query which fetches data from DB1 and inserts to DB2.
    so the select query will fetch the records that were INSERTED to DB1 and records that were UPDATED to DB1 and needs to insert/update to DB2 table.
    Now the issue is i am able to insert the records but not able toupdate the records to DB2 table due to primary key issue.
    im message mapping
    sender message type is as follows:
    <src_message1>
    ----<row>
    -------<fieldA>
    -------<filedB>
    -------<filedC>
    Receiver message type as follows:
    <trgt_message1>
    ----<STATEMENT_1>
    ----<TABLE_NAME>
    ----<ACTION> INSERT
    ----<TABLE>
    ----<ACCESS>
    ----<field1> primary key
    ----<field2>
    ----<field3>
    ----<field4>
    ----<KEY>
    ----<field1>
    ----<field2>
    ----<field3>
    ----<field4>
    my query in sender channel is : select filedA, filedB, filedC from test_table where createdate=sysdate or updatedate=sysdate
    so it feteches the data from DB1 and inserting to DB2 but not updating the records to DB2 due to primarykey issue.
    please suggest how to solve ....will it solve by using UPDATE_INSERT for action?
    Best Regards,SARAN

    Hi Nagarjuna,
    i have done the following changes to target mapping structure;
    1. action as UPDATE_INSERT
    2.  in access tab, i had mapped fieldDate to field4.
    3. in Key tab, i assigned the sysdate to field4.
    but issue still exist. could you please check my above changes are correct or not. if wrong please provide me the details that needs to be done.
    thanks in advance.
    i'm providing the error details again:
    my query in sender channel is : select filedA, filedB, filedC, FiledDate from TEST_TABLE where fieldDate=sysdate or updatedate=sysdate
    it returns 4 records as follows:
    fieldA--fieldB-fieldC---fieldDate
    1001----EU----  1----
        2011-11-10
    1002----CN----  0----
         2011-11-10
    1003----AP---- 1----
          2008-03-15 (already exist in DB2)
    1004----JP----  1----
        2007-04-12 (already exist in DB2)
    the first two records are created today and remaining 2 records are updated the fieldC from 0 to 1 ( in DB1 )
    while inserting these 4 records to DB2, we get the following error "java.sql.SQLException: ORA-00001: unique constraint (data.TEST_TABLE_PK) violated" .
    Best Regards,SARAN

  • Insert,update and delete data in a table using webdynpro for abap

    Dear All,
    I have a requirement to create a table allowing the user to add rows in it and update a row as well as delete a row from that table.To do this I guess I have to make use of ALV.But using ALV I am not able to enter data to a table where as I can make a column editable delete a row etc. please guide me to perform these operations(insert,update and delete) on table.
    Thanks,
    Reddy.

    Hi Sridhar,
    By using ALV you can do all insert delete etc things. if you want to edit i mean you can yenter data in ALV.
    Check this...
    http://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/3133474a-0801-0010-d692-81827814a5a1
    Editing alv in web dynpro
    editing rows in alv reports
    Re: editing rows and columns in alv reports in webdynpro abap
    Cheers,
    Kris.

  • I am trying to gather date and cost data from one table to another:

    Appreciate some help on this one.
    I have two tables.
    Table One showing a number of columns; including column 'F' Expiry / Renewal and column 'I' Charge (in £s)
    On Table Two I have 5 columns where each column represents a year (2011, 2012 etc) and 12 Rows, each representing the 12 Months (January, December etc)
    I was hoping to gather the Charge information on Table Two by using the following; changing the month and year after the "= as necessary
    =SUMIF('Expires / Renewal',"=November 2011",(Gross charge))
    The problem I have is that column F in Table One is shown as dd month yyyy (15 July 2011) and Table Two will only calculate those months in column F Table One if the day recorded is the first of the month. For example: 1 November 2011 (NOT 01 November 2011).
    You will be able to see from my screen capture of Table Two that there is a discrepancy between my 'Check Totals' column B and Column C. Column B has been calculated manually including all day ranges per month from 1st - 31st. Column C has been auto calculated by using variations of the formula above (per row) but is only picking up those dates with the first being recorded.
    NB: My fanancial year runs from Oct - Sept hence the layout attached. I am also in the UK hence the date format. Using Numbers 09
    Thanks in advance.
    Glen

    Glen,
    Here's a suggestion you can think about, after which you can work out the details. If you need more help, just ask.
    I would add a column, say Column J, to your data table (first table), hide later, that has the following expression to create a date code for your SUMIF expression to use as a condition.:
    =MONTH(F)&"-"&YEAR(F)
    Your summary then could use the expression shown in this screen shot, if you were to use a calendar year approach, and a modified expression for your fiscal year, which you may work out on your own:
    Regards,
    Jerry

  • What is the Best way To Copy and paste data from 1 book to another

     I have 18 sheets in 5 different books that I want to extract data from specific cells.  What is the best way to do this?  Example:  1 sheet is called Numbers E-O1 data in 13:WXYZ. The data updates and moves up 1 row every time I enter
    a new number. So let's say I enter the number 12. Through a lot of calculations the output goes in 13:WXYZ. To what I call a counter which is a 4 digit number.  Anyways, how can I send that 4 digit number to a totally different sheet?  To bullet
    what I'm talking about
    data in cells Row 13:WXYZ in book called Numbers sheet E-O1
    send data to book called "Vortex Numbers" Sheet E-O row 2001:CDEF
    What formula or Macro can I use to make this work?
    thank you!

    Hello Larbec,
    Syntax:
    '[BookName]SheetName'!Range
    Enter in cell  2001:CDEF:
    ='[Numbers]E-O1'!13:WXYZ
    This assumes that the file is open in Excel. Otherwise you need to add the path:
    'ThePath[BookName]SheetName'!Range
    Best regards George

  • How to copy all the data from old computer to new computer (server)

    Dear all,
    As I want to upgrade the server from old computer to a new one.
    I want to ask how and easy way to copy all of table, sequence, ......data from existing old computer to new computer.
    The old server is window 2000 Server with oracle 10g
    The new server may window 2003 Server with oracle 10g
    Thanks a lot
    Francis SZE

    As far as I can see you are copying from db10g for windows to another host on the same platform and same OS, so a simple cold backup taken from the source database can be restored at the target host. You must first make sure the configuration files and service be created prior to performing the database startup procedure at the target host. You may also as suggested, perform an rman duplication task
    ~ Madrid

  • How to Select Data from different Tables Using Linq

    Hi,
    I have two different tables, I just want to collect data from tables using Linq to SQL Queries.
    The tables looks like This 
    ID Name ImageUrl 
    Other Table is
    ID EmpID CheckInTime CheckOutTime 
    What I want to Collect data from CheckInTime and want to place it in a that is in a list view
    Same thing I want to do it for CheckOutTime And One thing I want to tell is both tables are joined by a FK EmpID with ID.
    What Are the suggestions for me 
    I have Used this code
    var data = from emp in db.Employees
    join chk in db.CheckInCheckOuts on emp.ID equals chk.EmpID
    select new EmployeeCheckInOut
    Name = emp.Name,
    ImageUrl = emp.ImageUrl,
    CheckIn = emp.CheckInCheckOuts,
    CheckOut = emp.CheckInCheckOuts
    Here the CheckInCheckOuts is another table, I don't how do I access fields of the Other table "CheckInCheckOuts"
    Thank you
    Ali

    Mitja,
    Kind of Tables, I don't Know but I can Tell you that these are Two table, first Table Have Data in It, Name, ImageUrl I have filled this table with names and ImageUrls And are string type.Other Table is for the CheckInTime And CheckOutTime of the employee.
    What I need that when I click on the Image button it Should displays The Current Datetime into the label below the Image button.
    So I have Problem accessing my CheckInCheckOut Table because I may not have Idea about.Did you understand what I need to do, if you have more question please ask to me.
    Thanks
    Ali

Maybe you are looking for