Updating one table based on another

Ok, that sounds a little confusing, but this is what I want to do:
Table A is my source table and is a temp table and will be reloaded daily.
Table B is my target table.
What I want to do is update Table B using a subset of Table A based on a date within Table B. A simple psuedo code would look like:
update Table B
insert * from Table A where Table B.datefield <> Table A.datefield.
Both tables contain the same data elements, so the structure is an exact 1 to 1 match.
Table B was initially created from Table A using the copy command to do an intial load. From this point forward, I just need to update Table B with new data from Table A, which has data loaded into it throughout the day. My idea is to grab just the data that isn't in Table B once a day.
I'm open to all suggestions or ideas............
Doug

By cracky, I think that merge thing is just what I'm looking for.
In theory the data in Table A will contain the data in Table B, plus newer data. The older data in Table A is stagnant, meaning that that table is just appended to. The problem is, Table A is periodically trimmed by the application. Table B is to be used for compiling all the data and reporting trend and historical data.
More, specifically, Table A is the History table in HP Openview. Table B will be a table in HP Performance Insight. Since theses are 2 totally seperate databases, I will need to copy over the OpenView History table to a temp table in PI nightly, then cull out the records that were added during that day and place those and only those into the PI table for reporting.
I'll give the merge command a try. I think it will do exactly what i need.
Thanks,
Doug

Similar Messages

  • How to update one table based on another table ??

    Hello Friends:
    I am trying to run the following query in oracle but it won't run.
    UPDATE BOYS
    SET
    BOYS.AGE = GIRLS.AGE
    FROM GIRLS
    WHERE
    BOYS.FIRSTNAME = GIRLS.FIRSTNAME AND
    BOYS.LASTNAME = GIRLS.LASTNAME;
    This query runs fine in sql server but in oracle its saying can't find "SET". PLease tell me what is the correct syntax in oracle to update one table based on another table.
    thanks

    See if this helps.
    If you wrote an SQL statement:
    update boys set age = 10;
    Every row in the boys table will get updated with an age of 10. But if you wrote:
    update boys set age = 10
    where firstname = 'Joe';
    Then only the rows where the firstname is Joe would be updated with an age of 10.
    Now replace the 10 in the above statements with (select g.age from girls g where g.firstname = b.firstname and g.lastname = b.lastname) and replace where firstname = 'Joe' in the second statement with where exists (select null from girls g where g.firstname = b.firstname and g.lastname = b.lastname). The same concepts apply whether 10 is an actual value or a query and whether you have a where clause with the update statement to limit rows being updated.
    About the select null question regarding the outer where clause:
    Since the query is checking to see if the row in the girls table exists in the boys table what the column is in this select statement doesn't matter, this column isn't being used anywhere. In this case Todd chose to use null. He could have also used a column name from the table or a lot of times you'll see the literal value 1 used here.

  • Update vs Merge - Updating one table based on values in another

    Hello
    I have two tables lets say TAB_A and TAB_B. I altered table B to include a new column from table A
    I wrote a merge statement as follows to merge the data
    MERGE INTO TAB_A
    USING TAB_B
    ON (TAB_A.SECURITYPERSONKEY=TAB_B.SECURITYPERSONKEY)
    WHEN MATCHED THEN
      UPDATE SET TAB_A.PPYACCOUNT=TAB_B.PPYACCOUNT;
    I know INSERT is for inserting new records
    UPDATE to my knowledge is to modify currently existing records (loosely)
    MERGE is one I rarely used, until this particular scenario.
    The code works perfectly fine, but I was wondering how could I write an update statement? Or in this scenario should I even be using an update statement?

    The MERGE is good and performs well, although it malfunctions (sometimes updating data wrongly) if the destination is a view with INSTEAD OF triggers.
    The UPDATE with similar performance to the MERGE depends on SECURITYPERSONKEY being a unique or primary key on TAB_B. It is:
    update (select TAB_A.PPYACCOUNT a_PPYACCOUNT, TAB_B.PPYACCOUNT b_PPYACCOUNT
            from TAB_A JOIN TAB_B on TAB_A.SECURITYPERSONKEY=TAB_B.SECURITYPERSONKEY)
    SET A_PPYACCOUNT=B_PPYACCOUNT;
    This can set multiple columns. It also currently doesn't work on a view with INSTEAD OF triggers.
    Frank's update also works with multiple columns (eg also updating col2 and col2), with this syntax:
    UPDATE  tab_a
    SET     (ppyaccount, col2, col3) = (
                             SELECT  ppyaccount, col2, col3
                             FROM   tab_b
                             WHERE  securitypersonkey  = tab_a.securitypersonkey
    WHERE   EXISTS       (
                             SELECT  ppyaccount
                             FROM    tab_b
                             WHERE   securitypersonkey  = tab_a.securitypersonkey

  • Update one table based on condition from another table using date ranges

    Hello!
    I have two tables:
    DateRange (consists of ranges of dates):
    StartDate            FinishDate
            Condition
    2014-01-02
          2014-01-03           true
    2014-01-03     
     2014-01-13          
    false
    2014-01-13      
    2014-01-14           true
    Calendar (consists of three-year dates):
    CalendarDate    IsParental
    2014-01-01
    2014-01-02
    2014-01-03
    2014-01-04
    2014-01-05
    2014-01-06
    2014-01-07
    2014-01-08
    2014-01-09
    2014-01-10
    I want to update table Calendar by setting  IsParental=1
      for those dates that are contained in table DateRange between
    StartDate and FinishDate AND Condition  IS TRUE.
    The query without loop should look similar to this but it works wrong:
    UPDATE
    Calendar
    SET IsParental = 1
     WHERE
    CalendarDate   BETWEEN
    (SELECT
    StartDate 
    FROM  DateRange
    WHERE Calendar.  CalendarDate   = DateRange. StartDate
               AND   
    (SELECT StartDate 
    FROM  DateRange
    WHERE Calendar.  CalendarDate   = DateRange. FinishDate
    AND Condition
     IS TRUE
    Is it possible to do without loop? Thank you for help!
    Anastasia

    Hi
    Please post DDL+DML next time :-)
    -- This is the DDL! create the database structure
    create table DateRange(
    StartDate DATE,
    FinishDate DATE,
    Condition BIT
    GO
    create table Calendar(
    CalendarDate DATE,
    IsParental BIT
    GO
    -- This is the DML (insert some sample data)
    insert DateRange
    values
    ('2014-01-02', '2014-01-03', 1),
    ('2014-01-03', '2014-01-13', 0),
    ('2014-01-13', '2014-01-14', 1)
    GO
    insert Calendar(CalendarDate)
    values
    ('2014-01-01'),
    ('2014-01-02'),
    ('2014-01-03'),
    ('2014-01-04'),
    ('2014-01-05'),
    ('2014-01-06'),
    ('2014-01-07'),
    ('2014-01-08'),
    ('2014-01-09'),
    ('2014-01-10')
    select * from DateRange
    select * from Calendar
    GO
    -- This is the solution
    select CalendarDate
    from Calendar C
    where EXISTS (
    select C.CalendarDate
    FROM DateRange D
    where C.CalendarDate between D.StartDate and D.FinishDate and D.Condition = 1
    UPDATE Calendar
    SET IsParental = 1
    from Calendar C
    where EXISTS (
    select C.CalendarDate
    FROM DateRange D
    where C.CalendarDate between D.StartDate and D.FinishDate and D.Condition = 1
    [Personal Site] [Blog] [Facebook]

  • Change field value in a table, based on another field value in the same row (for each added row)

    Please Help, I want to change field value in a table, based on another field value in the same row (for each added row)
    I am using this code :
    <HTML>
    <HEAD>
    <SCRIPT>
    function addRow(tableID) {
    var table = document.getElementById(tableID);
    var rowCount = table.rows.length;
    var row = table.insertRow(rowCount);
    var colCount = table.rows[0].cells.length;
    for(var i=0; i<colCount; i++ ) {
    var newcell = row.insertCell(i);
    newcell.innerHTML = table.rows[1].cells[i].innerHTML;
    switch(newcell.childNodes[0].type) {
    case "text":
    newcell.childNodes[0].value = "";
    break;
    case "checkbox":
    newcell.childNodes[0].checked = false;
    break;
    case "select-one":
    newcell.childNodes[0].selectedIndex = 0;
    break;}}}
    function deleteRow(tableID) {
    try {var table = document.getElementById(tableID);
    var rowCount = table.rows.length;
    for(var i=0; i<rowCount; i++) {
    var row = table.rows[i];
    var chkbox = row.cells[0].childNodes[0];
    if(null != chkbox && true == chkbox.checked) {
    if(rowCount <= 2) {
    alert("Cannot delete all the rows.");
    break;}
    table.deleteRow(i);
    rowCount--;
    i--;}}}catch(e) {alert(e);}}
    </SCRIPT>
    </HEAD>
    <BODY>
    <INPUT type="button" value="Add Row" onClick="addRow('dataTable')" />
    <INPUT type="button" value="Delete Row" onClick="deleteRow('dataTable')" />
    <TABLE id="dataTable" width="350px" border="1">
    <TR>
    <TD width="32"></TD>
    <TD width="119" align="center"><strong>Activity</strong></TD>
    <TD width="177" align="center"><strong>Cost</strong></TD>
    </TR>
    <TR>
    <TD><INPUT type="checkbox" name="chk"/></TD>
    <TD>
    <select name="s1" id="s1">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    </select>
    </TD>
    <TD><input type="text" name="txt1" id="txt1"></TD>
    </TR>
    </TABLE>
    </BODY>
    </HTML>

    Hi,
    Let me make sure u r working with table control.
    First u have to create a event(VALIDATE) to do the validation.
    Inside the event,
    1. First get the current index where user has pointed the curson
    2. Once u get the index read the internal table with index value.
    3. Now u can compare the col1 and col2 values and populate the error message.
    1. DATA : lo_elt TYPE REF TO if_wd_context_element,
                   l_index type i.
    lo_elt = wdevent->get_context_element( name = 'CONTEXT_ELEMENT' ).
         CALL METHOD LO_ELT->GET_INDEX( RECEIVING  MY_INDEX = l_index.
    above code should be written inside the event.
    Thanks,

  • Updating one table with mult. table where clause

    I'm having problems with my update statement. I want to update one table that has a mulitple table where clause. Not sure how to accomplish this. Here is what I have so far.
    update lawson.apvenmast a
    set vendor_status = 'I'
    where ((select * from apinvoice i
    where i.due_date <= TO_DATE('20011231', 'YYYYMMDD') and
    i.vendor = a.vendor)
    ((apvenmast.ven_class = 'INS') or
    (apvenmast.ven_class = 'REF')));
    Am I on the right track?
    thanks in advance for any help.
    Lisa Mears

    A lot is missing.
    where ((select * from apinvoice iA where clause should be like
    where <something> IN (select <something> from ...)
    ((apvenmast.ven_class = 'INS') or
    (apvenmast.ven_class = 'REF')));Where does this belong? There is no AND or OR with these two lines.
    Check your table aliases too.

  • Best way to create a table based on another table

    Hello,
    I am trying to create a table based on another table with all the data in it. It has large data.
    create table <tablename> as select * from table1.
    Is this the best way of doing it or is there any other way. please advice.
    thanks

    I am suggested to create new table as
    create table <newtable> as
    select * from <oldtable> where rownum < 1;
    then
    alter table <newtable> compress;
    then
    insert /*+ append */ into <newtable> as select * from <oldtable>;
    but i getting an error saying missing values key words ora- 00926.
    please advice

  • Updating one table is updating ALL the materialized views

    We have a number of tables and also a number of materialized views that are interconnected. For some unexplained reason, when we update one table that should refresh one materialized view, all the materialized views are refreshed. It's causing massive bottlenecks on our system and we can't find the cause. Does anyone have any thoughts?

    "when we update one table that should refresh one materialized view, all the materialized views are refreshed" --If that table is used in the creation of all materialized views,then it will try to refresh all of them..(ON COMMIT REFRESH)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Comparing Two tables with 300k records and update one table

    Could you let me know how to compare two tables having 300k records and update one table.below is the scenario.
    Table Tabl_1 has columns A,B and Tabl_2 has columns B,new_column.
    Column B has same data in both the tables.
    I need to update Tabl_2 in new_column with Tabl_1 A column data by comparing B column in both tables.
    I m trying to do using PLSQL Tables.
    Any suggestion?
    Thanks.

    Hi,
    Whenever you have a problem, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables involved, so that the people who want to help you can re-create the problem and test their ideas.
    Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
    If you're asking about a DML statement, such as UPDATE, the CREATE TABLE and INSERT statements should re-create the tables as they are before the DML, and the results  will be the contents of the changed table(s) when everything is finished.
    Always say which version of Oracle you're using (for example, 11.2.0.2.0).
    See the forum FAQ: https://forums.oracle.com/message/9362002
    ef2019c7-080c-4475-9cf4-2cf1b1057a41 wrote:
    Could you let me know how to compare two tables having 300k records and update one table.below is the scenario.
    Table Tabl_1 has columns A,B and Tabl_2 has columns B,new_column.
    Column B has same data in both the tables.
    I need to update Tabl_2 in new_column with Tabl_1 A column data by comparing B column in both tables.
    I m trying to do using PLSQL Tables.
    Any suggestion?
    Thanks.
    Why are you trying to use PL/SQL tables?  If tabl_1 and tabl_2 are regular database tables, it will be much simpler and faster just to use them.
    Depending on your requirements, you can do an UPDATE or MERGE, either in SQL or in PL/SQL.

  • How to update one table from another

    I am creating scripts in Oracle 10g. I have a table that has data corruption on three date fields.
    I created a table with the following sql of all the affected rows:
    CREATE TABLE LSU_INTER_FIX_DATE AS
    select request_id,received_date,planned_start_date, actual_start_date
    from lsu_inter2_requests_t
    where received_date < to_date('01-JAN-1900')
    OR planned_start_date < to_date('01-JAN-1900')
    OR actual_start_date < to_date('01-JAN-1900')
    I then repaired all of the rows with three data fixes
    UPDATE LSU_INTER_FIX_DATE
    SET received_date = TO_CHAR(received_date,'YY-MON') ||'-'||(TO_CHAR(received_date,'RRRR') + 2000)
    where received_date < to_date('01-JAN-1900')
    UPDATE LSU_INTER_FIX_DATE
    SET planned_start_date = TO_CHAR(planned_start_date,'YY-MON') ||'-'||(TO_CHAR(planned_start_date,'RRRR') + 2000)
    where planned_start_date < to_date('01-JAN-1900')
    UPDATE LSU_INTER_FIX_DATE
    SET actual_start_date = TO_CHAR(actual_start_date,'YY-MON') ||'-'||(TO_CHAR(actual_start_date,'RRRR') + 2000)
    where actual_start_date < to_date('01-JAN-1900')
    I now want to update the original base table with the corrected data so I wrote the following SQL UPDATE command:
    UPDATE lsu_inter2_requests_t aaa
    SET aaa.received_date = bbb.received_date
    FROM LSU_INTER_FIX_DATE bbb WHERE aaa.request_id = bbb.request_id
    When I run this sql Oracle returns the error “ORA-00933 SQL command not properly ended.” How do I update multiple rows in one table from another table that share the same primary key?

    Comet wrote:
    I am creating scripts in Oracle 10g. I have a table that has data corruption on three date fields.
    I created a table with the following sql of all the affected rows:
    CREATE TABLE LSU_INTER_FIX_DATE AS
    select request_id,received_date,planned_start_date, actual_start_date
    from lsu_inter2_requests_t
    where received_date < to_date('01-JAN-1900')
    OR planned_start_date < to_date('01-JAN-1900')
    OR actual_start_date < to_date('01-JAN-1900')
    I then repaired all of the rows with three data fixes
    UPDATE LSU_INTER_FIX_DATE
    SET received_date = TO_CHAR(received_date,'YY-MON') ||'-'||(TO_CHAR(received_date,'RRRR') + 2000)
    where received_date < to_date('01-JAN-1900')
    UPDATE LSU_INTER_FIX_DATE
    SET planned_start_date = TO_CHAR(planned_start_date,'YY-MON') ||'-'||(TO_CHAR(planned_start_date,'RRRR') + 2000)
    where planned_start_date < to_date('01-JAN-1900')
    UPDATE LSU_INTER_FIX_DATE
    SET actual_start_date = TO_CHAR(actual_start_date,'YY-MON') ||'-'||(TO_CHAR(actual_start_date,'RRRR') + 2000)
    where actual_start_date < to_date('01-JAN-1900')
    I now want to update the original base table with the corrected data so I wrote the following SQL UPDATE command:
    UPDATE lsu_inter2_requests_t aaa
    SET aaa.received_date = bbb.received_date
    FROM LSU_INTER_FIX_DATE bbb WHERE aaa.request_id = bbb.request_id
    When I run this sql Oracle returns the error “ORA-00933 SQL command not properly ended.” How do I update multiple rows in one table from another table that share the same primary key?I am not convinced you have what you think you have
    >
    UPDATE LSU_INTER_FIX_DATE
    SET received_date = TO_CHAR(received_date,'YY-MON') ||'-'||(TO_CHAR(received_date,'RRRR') + 2000)
    where received_date < to_date('01-JAN-1900')
    When you want to produce a DATE datatype when starting with a string,
    you must use TO_DATE() on the SET line!
    (TO_CHAR(received_date,'RRRR') + 2000)since when do you do add characters (from TO_CHAR) with a constant number (2000)?
    You should NEVER EVER rely on implicit datatype conversion
    Edited by: sb92075 on Jul 27, 2011 7:09 PM

  • Update a table based on Min value of a column of a Another Table.Pls Help.

    Dear All,
    Wishes,
    Actually I need update statement some thing like below scenario...
    Data in table is like below:
    I wrote a query to fetch data like below ( actually scenario is each control number can have single or multiple PO under it ) (i used rank by to find parent to tree like show of data)
    Table: T20
    Control_no        P_no  Col3
    19950021     726473     00
    19950036      731016     00
    19950072     731990     00
                     731990 01
    19950353     734732     00
                     734732 01
    19950406     736189     00
                 736588     01
                 736588     02
                 736588     03                
    Table : T30
    Control_no      P_no              col3
    19950021     726473 
    19950036     731016
    19950072     731990     
                 731990     
    19950353     734732     
                  734732     
    19950406     736189     
                  736588     
                  736588     
                   736588     
      Now requirement is I need to update Table T30's col3 (which do have values in T20 but not this table) in such a way that , It should take MIN (COL3) from T20 and then update that value to related Col3)
    Better I can explain through below new data format in T30 after update:
    After update it should like:
    Table : T30
    Control_no       P_no    col3 (this is updated column)
    19950021     726473   00  -- as this is min value for Pno 726473 belongs to Control NO 199950021 in Table T20 above
    19950036     731016   00  -- as this is min value for Pno 726473 belongs to Control NO 199950021 in Table T20 above
    19950072     731990   00  -- see here..both Pno should updated as '00' as MIN value col3 in Table T20 related to this
                 731990      00     record is '00'  (out of 00,01 it should select 00 and update that value here)
    19950353     734732      00  -- same again both Pno should updated as '00' as MIN value col3 in TableT20 related to this
                 734732      00     record is '00'  (out of 00,01 it should select 00 and update that value here)
    19950406     736189      00  -- As there is single col3 value in T20, 00 should be updated here.
                 736588      01  --  Here it should update col3 as '01' since for this pno(736588)
                 736588      01  --  Here too it should update col3 as 01 per requirement ,minimum value of this pno in T20
                 736588      01  --     same here too.. Sorry if my post formatting is not good...
    Hope i am clear in my requirement..(update T30 col3 based on min value of col3 of related records)
    Please suggest some update sql for this...(ideas would be great)
    I am using oracle 10 g version soon will be migrated to 11g..
    Regards
    Prasanth
    Edited by: Onenessboy on Oct 20, 2010 12:13 PM
    Edited by: Onenessboy on Oct 20, 2010 12:15 PM

    Onenessboy wrote:
    I am really sorry, my post so nonsense in look..
    I used to use for actuall code..
    the out put i tryped, i used [pre] , [/pre] but still does not look good..
    hmm..thanks for your suggestion hoek..
    so any ideas about my requirement...I would suggest spending a bit more time trying hoek's suggestion regarding {noformat}{noformat} tags instead of repeatedly asking for more help.
    Because to understand your requirement, people are going to have to read it first.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • How to update one lov based on value selected from another lov.

    Hi ,
    I have a form in which I created the 2 LOVs for my event_date field and event_name field each which is stored in one table.
    t I want to update the event_date LOV everytime event_name is selected.
    How can I achieve this.
    Thanks.
    Neeti.

    Hi,
    You can do this using dynamic LOVs. Here are the steps for populating a employee LOV on selecting a department.
    1) Create a dynamic lov say emloyee_lov with a bind variable like this
    select empno,ename from scott.emp
    where deptno = :dept
    2) Create a form on scott.emp.
    3) In the empno field which should be a LOV type of field, associate it with
    the above employee LOV.
    4) Then set the binding(s) for the bind variable(s) defined in the lov by
    selecting the deptno column.
    This would help.
    Thanks,
    Sharmila

  • Updating database table based on BAPI response in case of error

    Dear Experts,
    My scenario includes pulling records from database stagging table, and push one record at a time to BAPI_ALM_NOTIF_CREATE.
    I am using sender JDBC adapter(with select query and update query to mark records as processed).
    My question is : Once XI selects records, immediately status is updated in stagging table for the selected records as processed. what if BAPI could not create document? In this case I need to update status of that record as "Not processed".
    What should I use?
    If BPM, then please tell me the steps.
    Is this possible without BPM?
    What are the chances of failure between XI and BAPI?
    Please provide your inputs.
    Thank you.
    Div

    >
    S.R.Suraj wrote:
    > Hi Divyesh,
    >
    > Your steps are correct..
    >
    > 1. JBDC will read record with code = 0 and make it 1...
    > 2. Once the bapi process is completed all these read records shoudl be made as 2 (if completed successful) else 0 if bapi went into some error.. so that again the jdbc adapter can poll these records and give back to bapi for processing...
    >
    > Now your questions
    > >>So after selection and updation only proxy call will be done right? So for every polling of jdbc adapter ,proxy call will happen?
    > YEs every poll of jdbc will result in a proxy call and every time it will contain next set of records (as the earlier one have already marked as 1)
    >
    > >>How to achieve this?
    > Since this is a synchronous scenario JBDC->XI->Proxy and reverse, I have suggested to use responseonewaybean as a module in sender jdbc adapter (because sender jdbc cannot act synchronously thats why you need to use this module)..
    >
    > >>Do i need to use BPM? please suggest steps.
    > and if this is not working then go for BPM..the steps as i mentioned in my first thread..
    >
    > Regards
    > Suraj
    Hi Suraj,
    Thanks a lot for your support.
    It would be good if you can provide your inputs.
    Stagging table records status:
    Flag = 0 (XI will poll records)
    Flag = 1(XI has polled records and XI will se tthis flag by JDBC adapter)
    Flag =2 (should be done based on response from Proxy Tables parameter) Proxy will set tables parameter which will include info on error message and type.
    (Now based on new requiremets: for error records status should not be reset to 0 so that XI can poll records again, now stagging table should contain error records(for which proxy can not create notification in SAP) with error message and status flag 2)
    Now scenario would be JDBC to Proxy.
    Polling interval for JDBC adapter should be 1 minute.
    So I think status 0 to 1 will be done by XI after immediately selecting records.
    But how about Status 2 that has to be set only for error records only and  with error information.
    I have to update stagging table records with status 2 and error info based on proxy table response. How this can be done?
    This updation will be done in case of error only.
    I was thinking this aproach:
    We can have two interfaces.
    First interface will be jdbc to proxy:
    JDBC adapter select and update records with flag =1 and then send to proxy call and create document in SAP. At SAP side if document can not be created then they will store that error info in some table.
    Second Interfgace:
    Client SAP Proxy will periodically run and send these error records info to XI and XI will update stagging table records accordingly.
    Suraj, What is your sugestion in this solution? Do I need to use Responseonewaybean?
    Thanks Suraj
    Div

  • Trying to update one table from a second table when data is different

    Hello;
    I have a the same table in two databases. The database are connected with a DB Link. I am trying to update one of the tables based on the data in the second table when the EMP_ID matches but the LAST_NAME does not match.
    The table(s) look like:
    Table Name:EMP
    EMP_ID
    LAST_NAME
    FIRST_NAME
    MIDDLE_INITIAL
    My SQL is:
    update EMP TARGET
        set (TARGET.LAST_NAME, TARGET.FIRST_NAME,TARGET.MIDDLE_INITIAL) = (
            select SOURCE.LAST_NAME, SOURCE.FIRST_NAME, SOURCE.MIDDLE_INITIAL
            from EMP@OTHER_DB SOURCE where
            TARGET.PHYSICIAN_ID = SOURCE.PHYSICIAN_ID
            and TARGET.LAST_NAME <> SOURCE.LAST_NAME); This returns an update count of all the rows not the few that I want.
    Any help would be great!

    Hi,
    Sky13 wrote:
    Hello;
    I have a the same table in two databases. The database are connected with a DB Link. I am trying to update one of the tables based on the data in the second table when the EMP_ID matches Do you <b>physician</b>_id?
    but the LAST_NAME does not match.
    The table(s) look like:
    Table Name:EMP
    EMP_ID
    LAST_NAME
    FIRST_NAME
    MIDDLE_INITIAL
    My SQL is:
    update EMP TARGET
    set (TARGET.LAST_NAME, TARGET.FIRST_NAME,TARGET.MIDDLE_INITIAL) = (
    select SOURCE.LAST_NAME, SOURCE.FIRST_NAME, SOURCE.MIDDLE_INITIAL
    from EMP@OTHER_DB SOURCE where
    TARGET.PHYSICIAN_ID = SOURCE.PHYSICIAN_ID
    and TARGET.LAST_NAME <> SOURCE.LAST_NAME); This returns an update count of all the rows not the few that I want.
    Any help would be great!There's no WHERE clause in that UPDATE statement, so every row of the target table will be modified.
    if you only want to modify the rows that have a match in the source table, then add a WHERE clause (perhaps "WHERE EXISTS (...) with a sub-query very miuch like the one you already have), or use MERGE instead of UPDATE.
    If you'd like help, post CREATE TABLE and INSERT statements to re-create the tables as they exist before the UPDATE, and also post the contents of the changed table after the UPDATE.
    Always say which version of Oracle you're using.
    Perhaps you want something like this:
    {code}
    MERGE INTO     emp     target
    USING     (
         SELECT     o.emp_id
              ,     o.last_name
              ,      o.last_name
              ,      o.middle_initial
              FROM     emp@other_db     o
              JOIN     emp          t ON     o.emp_id     = t.emp_id
                             AND     o.last_name     != t.last_name
         )          source
    ON     (target.emp_id     = source.emp_id
    WHEN MATCHED THEN UPDATE
    SET     target.last_name     = source.last_name
    ,     target.first_name     = source.first_name
    ,     target.middle_initial     = source.middle_initial
    {code}
    assuming emp is unique, at least in other_db.
    This will work in Oracle 10 (and up). In Oracle 9, MERGE always requires a WHEN MATCHED clause, so add one if you must. it doesn't matter what it does; the USING subquery will only return matches.
    Edited by: Frank Kulash on Oct 10, 2011 4:45 PM

  • Filter one table based on user selection

    Hi all ,
              I am creating simple employee data application in VC. It consists of roadmap. On first step user searches for employee by giving first name , last name then he searches for employee and all the data related to employee's is fetched out at one shot through BAPI_EMPLOYEE_GETDATA. Now after step one no of employee comes.
    When I select one record I want that for the selected rows employee's personal data should be fetched out from another table (which is populated during first BAPI call). so I want to pass the selected key value and filter that table based on passed value to table and filter the table .
    Kindly give a solution as to implement filter on a table without making another BAPI call .
    Thanks in advance
    Abhay

    Hi Abhay,
    There's a trick to get a 'dynamic' filter (i.e. a filter that filters on a value that can change) out of the normal static filters:
    Just click on the output of your data source, then 'configure' and on the '+'  - sign in the lower right corner. Add a boolean field called 'condition', for example. Then, you write the condition that filters out the row(s) that you need. In the filter that comes next in the dataflow you just filter on this 'condition' - field being true.
    Hope that helps,
    Sincerely,
    Florian

Maybe you are looking for