UPDATE COLS OF ONE TABLE FROM VALUES OF CERTAIN COLU OF ANOTHER TABLE

I have two tables table1               table1     
(col1,                (col1,
          col2,                col2,
          col3,                col3,
          col4,                col4,
          timeperiod)                timeperiod)
both have same column names. table1 has data for certain timeperiod. table2 also has the data for the same timeperiod. table2 has the correct data for col1, col2. I want to update the columns (col1, col2) in table1 with data from columns (col1, col2) in table2
and leave the col3, col4 in table1 untouched (no change). Each time I might have to update different columns. some tables have more than 20 columns. This is like, I need to update whatever field I want.
How do I do this with a script or block declaring variables. How do I control the update for certain columns. This is not a one time thing which I will be doing. I have to do this for several tables whenever the data is not right.
Thank you,
sv

Hi ,
you can use MERGE for this kind of situations....here i have given some samples...refer this...
MERGE INTO bonuses D
USING (SELECT employee_id, salary, department_id FROM employees
WHERE department_id = 80) S
ON (D.employee_id = S.employee_id)
WHEN MATCHED THEN UPDATE SET D.bonus = D.bonus + S.salary*.01
WHEN NOT MATCHED THEN INSERT (D.employee_id, D.bonus)
VALUES (S.employee_id, S.salary*0.1);
By this way u can update any no. of columns...I hope this will help you...
Thanks
Raj

Similar Messages

  • Need to compare values in two columns of one table against values in two columns in another table

    Hi, as the title reads, I'm looking for an approach that will allow me to compare values in two columns of one table against values in two columns in another table.
    Say, for instance, here are my tables:
    Table1:
    Server,Login
    ABCDEF,JOHN
    ABCDEF,JANE
    FEDCBA,SEAN
    FEDCBA,SHAWN
    Table2:
    Server,Login
    ABCDEF,JOHN
    ABCDEF,JANE
    FEDCBA,SHAWN
    In comparing the two tables, I'd like my query to report the rows in table1 NOT found in table2. In this case, it'll be the 3rd row of table one:
    Server,Login
    FEDCBA,SEAN
    Thanks.

    create table Table1([Server] varchar(50), Login varchar(50))
    Insert into Table1 values ('ABCDEF','JOHN'),('ABCDEF','JANE'),('FEDCBA','SEAN'),('FEDCBA','SHAWN')
    create table Table2([Server] varchar(50), Login varchar(50))
    Insert into Table2 values ('ABCDEF','JOHN'),('ABCDEF','JANE'), ('FEDCBA','SHAWN')
    select [Server] ,Login from Table1
    Except
    select [Server] ,Login from Table2
    select [Server] ,Login from Table1 t1
    where not exists(Select 1 from Table2 where t1.[Server] = t1.[Server] AND Login=t1.Login)
    drop table Table1,Table2

  • Passing value to bind variable of another table from one table

    hi,
    I have a multi select table. When one row is selected from this table (no button is clicked, only selection is done), an attribute from that selected row (say userid) should be passed to the bind variable of another table and the corresponding details of that particular userid should be displayed in the other table. When more than one row is selected, the other table should display no rows.
    My main problem is what code has to be written to pass value to bind variable and where it should be written.
    Please give me a detailed explaination as soon as possible.
    Thank you.

    Sorry, didnot add this. The table is multi select table.

  • How  to retrieve one row from the number of records in a table

    i want to retrieve the rows from the number of records in a table without using the perticular column name.

    select count(*) from table
    /If you have your table currently analyzed, and no changes have been made, then you could
    select num_rows from user_tables where table_name = 'table'

  • How to get save result from EXECUTE from a dynamic SQL query in another table?

    Hi everyone, 
    I have this query:
    declare @query varchar(max) = ''
    declare @par varchar(10)
    SELECT @par = col1 FROM Set
    declare @region varchar(50)
    SELECT @region = Region FROM Customer
    declare @key int
    SELECT @key = CustomerKey FROM Customer
    SET @query = 'SELECT CustomerKey FROM Customer where ' + @par + ' = '+ @key+ ' '
    EXECUTE (@query)
    With this query I want get col1 from SET and compare it to the column Region from Customer. I would like to get the matching CustomerKey for it.
    After execution it says commands are executed successfully. But I want to save the result from @query in another table. I looked it up and most people say to use sp_executesql. I tried a few constructions as sampled and I would always get this error: 
    Msg 214, Level 16, State 2, Procedure sp_executesql, Line 12
    Procedure expects parameter '@statement' of type 'ntext/nchar/nvarchar'.
    So the output should be a list of CustomerKeys in another table.
    How can I save the results from EXECUTE into a variable? Then I assume I can INSERT INTO - SELECT in another table. 
    Thanks

    CREATE TABLE Customer
    (CustomerKey INT , Name NVARCHAR(100));
    GO
    INSERT dbo.Customer
    VALUES ( 1, N'Sam' )
    GO
    DECLARE @query nvarchar(max) = ''
    declare @par varchar(10) = 'Name',
    @key varchar(10) = 'Sam'
    CREATE TABLE #temp ( CustomerKey INT );
    SET @query =
    insert #temp
    SELECT CustomerKey
    FROM Customer
    where ' + @par + ' = '''+ @key+ ''' '
    PRINT @query
    EXEC sp_executesql @query
    SELECT *
    FROM #temp
    DROP TABLE #temp;
    DROP TABLE dbo.Customer
    Cheers,
    Saeid Hasani
    Database Consultant
    Please feel free to contact me at [email protected] as well as on Twitter and Facebook.
    [My Writings on TechNet Wiki] [T-SQL Blog] [Curah!]
    [Twitter] [Facebook] [Email]

  • Total Last Cell from last row, last column into another table

    What I'm trying to do is create a sum in a final table that will add together all the last cell Sums in the last column, last row from all Ten tables.
    Example of where I want to get the information from:
    I know I could use something like this *=SUM(Table 1 :: K45,Table 2 :: D9)* but in the future I want to be able to add extra rows in the Ten tables and therefore have the final table calculate the last cell without having to manualy change the cell numbers in the Sum.
    Message was edited by: Pongify

    Pongify wrote:
    Your "Bingo" solution worked a treat, now with Ten tables do I have to put the code in the last table cell Ten times changing the table number on each?
    Yes you have, the last table is perfectly unable to guess from which table it must grab datas.
    CAUTION There is an oddity which I call a bug.
    If you rename one of the table from which you grab datas, the two first occurences (in bold) in the formula will be adjusted accordingly but the 3rd one will not (the underlined one).
    =INDIRECT(ADDRESS(ROWS( *Tableau 1* :: A),COLUMNS( *Tableau 1* :: 1:1),,,"_Tableau 1_"))
    My guess is that the designers forgot that this "string" has exactly the same status as the first two occurences. Of course it's reported to Apple but at this time, we have to live with it.
    Here is a slightly modifier formula:
    =INDIRECT(ADDRESS(ROWS(Tableau 1 :: A),COLUMNS(Tableau 1 :: $1:$1),,,"Tableau "&ROW()))
    I replaced 1:1 (in the COLUMNS operand) which was modified during the fill down process by $1:$1 which remains unchanged.
    As I am lazy, I modified the last reference to the tables so it is automatically adjusted during the fill down process (my tables are named Tableau 1 thru Tableau 10).
    Yvan KOENIG (from FRANCE dimanche 6 juillet 2008 16:27:30)

  • How do you sort a table that contains links to cells in another table?

    This is something that I used to be able to do in Numbers but since 2 or 3 updates ago this doesn't seem to happen.
    The problem I have is that I have a table that includes cells that are a sum of a number of cells from another table. When I try and sort by a column all the info in the cells change because, I imagine, the commands linking to the cells in the other table are offsetting by however many rows a particular row has moved.
    This didn't used to happen; it used to hold on to the same data and links regardless of where the sort function moved a row to.
    Had a look through the help pages but can't find anything about it. Has anyone found a way around this?
    Thanks in advance.
    Matt

    Hi mmatt,
    There are several ways to create sort-safe formulas. Without knowing what you are doing in your table it is hard to give specific advice but in general INDEX(), OFFSET() and I think INDIRECT() are sort safe- ie they will ocntinue to point to the same cell wherever they are in your sort.
    If you want specific advice you would need to provide more info.
    quinn

  • Copying more tables from a SQL Server db to another one - SSIS 2012

    Hi,
    in order to copy data of more tables (more an hundred) from a SQL Server db to a SQL Server destination db I'd like to use the Transfer SQL Server objects task, but the source tables belonged to the dbo schema and the destination schema is a different
    one.
    It seems that this task doesn't provide a such option.
    Any suggests to me, please?
    Thanks

    http://www.experts-exchange.com/Database/MS-SQL-Server/Q_26533111.html
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Is there any easy way to compare LIKE Addresses from one table, which contains 3rd party data, to another table, our database source

    We have a 3rd party that is supplying us data and we need to compare the addressing between the 3rd party data to our source database addressing. I'd like to make it somewhat flexible meaning I'd like to somehow use the LIKE comparison rather than comparing
    the exact address values. (I have noticed that the 3rd party addressing sometime has a leading <space> at the beginning of the address...why I'd prefer to use LIKE)
    Is there any easy way to do this? Or does this dictate using a CURSOR and processing through the CURSOR of 3rd party data and plugging in the address LIKE as dynamic SQL?
    Please let me know your thoughts on this and I appreciate your review and am hopeful for a reply.

    Yes, it's possible and there are a variety of options but it's may not be for the faint of heart.
    The last time I did it, I ended up taking several passes at the data.
    1st pass was a straight up comparison with no modifications or functions.
    2nd pass was the same but with all special characters removed.
    3rd pass involved splitting the numeric portion of address and comparing just the street numbers and used a double meta-phone function (kind of like a soundex on steroids) to compare the street names.
    Jason Long

  • Trigger to update field on a table with the sum of fields on another table

    My experience creating triggers and pl/sql in general can best be described in oracle terms as null. I've been practicing by creating tables and applications on my personal home server to help me with some of my work related tasks. Right now I'm trying to create a trigger that will, after insert, update, delete on the assignment_time_track table update the time_spent field on the assignments table with the sum of the time_spent fields on the assignment_time_track table. Hopefully that run on sentence there is clear to people other than myself. I've attempted to script this on my own using the trigger creation tool for Oracle Database Express Edition but I get the following error:
    Trigger create was not successful for the following reason:
    ORA-06552: PL/SQL: Compilation unit analysis terminated ORA-06553: PLS-320: the declaration of the type of this expression is incomplete or malformed
    Here is my attempt at creating the trigger on my own.
    create or replace trigger "ASSIGNMENT_TIME_TRACK_T1"
    AFTER
    insert or update or delete on "ASSIGNMENT_TIME_TRACK"
    for each row
    begin
    update assignments
    set time_spent = (select sum(time_spent)
    from assignment_time_track
    where assignment_time_track.name = assignments.name);
    end;
    If what I've posted isn't clear or more detail is needed, let me know and I'll respond with a complete description of both tables and my goals for each table. Thanks in advance for any help. I will also gladly accept links to tutorials or lessons that explain how to do this sort of thing.
    Edited by: bobonthenet on Mar 9, 2009 2:01 PM

    Hi,
    If the assignments table has only one row per assignment, why is the primary key the combination of name and time_spent? If you have two two assignments called "Lab Report", isn't it possible that you would spend the same amount of time on each of them? I suggest using a sequence to assign an arbitrary id number to each assignment, and use that as the primary key.
    What does each row in assuignment_time_track represent? It sounds like it is a chunk of time spent on one assignment (that is, you want to know that you spent 90 minutes on Tudesday morning working on some assignment, and that you spent another 30 minutes on Tuesday afternoon working on the same assignment). If so, then there should be a foreign key constraint in assignment_time_track referencing the primary key of assignemnt, and not the other way around.
    Alex is right; you can get the total time spent on each project in a query or view; there is no need to replicate that data.
    If you're new to Oracle and SQL, you should invest your time in getting more experience with the basics: everyday things like queries (using joins and GROUP BY) and views, and not spend much time on things that aren't used that much, like triggers.
    If you really did have to copy the data, then you could have a trigger on assignemnt_time_track that kept the total in assignment up to date, like this:
    UPDATE  assignment
    SET     total_time_spent = total_time_spent
                    + NVL (:NEW.time_spent, 0)
                             - NVL (:OLD.time_spent, 0);I suggest you name the column in assignment something different than the column in assignment_time_track, to reduce the risk of confusion. Also, since they represent different things, the same name can't be the most descripttive for each of them.
    In case you're wondering about the use of NVL, above: It allows the same statement to take care of the situation when you INSERT, UPDATE or DELETE a row in assignment_time_track. That is, if you UPDATE a row in assignment_time_track, and change the time_spent from 60 to 90, then you want to add the new time (90) and subtract the old time (60) fro the total_time_spent in assignment: that is, total_time_spent would increase by 30. If you INSERT a new row into assignment_time_track with time_spent=30, you just need to add the new time_spent (30): there is nothing to subtract. But rather than write an IF statement and a second UPDATE for that situation, you can just rely on hte fact that all :OLD values are NULL iwhen INSERTing, and treat that NULL as a 0. Likewise, when DELETing, all :NEW values are NULL..

  • Dreamweaver 8 - Height of tables keeps changing when images added to another table

    Greetings! i have a rather annoying problem on my hands with
    dreamweaver.
    Currently for a small college project i am being asked to
    design a small yet effective website to show students in the future
    what will be expected.
    So i've drawn up my template etc etc and all was going
    well.... i created a table with 2 columns, 1 row on the right side
    (where information shall be written) and 7 on the left hand column.
    At the very top of the left hand column i have a 250x250
    image and the other columns house several Sub links.
    Now upon typing information in the right hand column
    everything went well when browsing.....i then added pictures to the
    right hand column that will be clickable links for
    enlargements....of which dreamweaver had a small hissy fit and
    stretched the left hand columns 90% down the total width of the
    page....which a simple click on the border line solved and
    everything went back to proportion. BUT what i get when browsing is
    completley baffeling! Several of the left hand rows are stretched
    like crazy! and i havent a clue why! some screen shots will be
    viewable below...but i was wondering if any folk out there with any
    information into solving this problem could help!
    This is the dreamweaver view
    http://i37.photobucket.com/albums/e92/Kaoscontrol/Dreamweaverview.jpg
    And this is the browser view i get on every computer i've
    tried it on
    http://i37.photobucket.com/albums/e92/Kaoscontrol/Browserview.jpg
    If there is anyone that can help me out it would be greatley
    appretiated.
    Many thanks
    James

    Try changing this -
    action="Mailto: [email protected]"
    to this -
    action=''Mailto:[email protected]''
    I am doubtful that this will help, but give it a try.
    You do know how unreliable that method is, right?
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    ==================
    "alpha911" <[email protected]> wrote in
    message
    news:fit4am$nq7$[email protected]..
    > this is the script for the problem i am having. I am not
    getting any
    > email
    > when someone press send
    > <form name="frmsendmail" method="POST" >
    onSubmit="return
    > ValidationForm()">
    > <table width="80" height="386" border="0"
    align="center">
    >
    > <tr>
    > <td width="105"> </td>
    >
    > <td width="327"> </td><tr>
    > <td> </td>
    > <td> </td></tr>
    > <td align="right" class="text">Name :
    > <td><div align="left">
    > <input name="txtEmailfrm2" type="text" class="input"
    > id="txtEmailfrm22" size="30" maxlength="100">
    > </div>
    > <tr>
    > <td align="right" class="text">Email :
    > <td><div align="left">
    > <input name="txtEmailfrm2" type="text" class="input"
    > id="txtEmailfrm22" size="30" maxlength="100">
    > </div>
    > <tr>
    > <td align="right" class="text">Subject :
    > <td><div align="left">
    > <input name="txtSub2" type="text" class="input"
    id="txtSub22"
    > size="30" maxlength="100">
    > </div>
    > </tr>
    > <tr>
    > <td align="right" class="text">Mesage(body) :
    > <td><textarea name="txtMsg" cols="50" rows="10"
    class="input"
    > id="textarea"></textarea>
    > </tr>
    > <tr>
    > <td align="right">
    > <div align="right">
    > <input name="hidsubmit" type="hidden" id="hidsubmit"
    > value="true">
    > <input name="Submit" type="submit" class="input"
    > value="Send">
    > </div>
    > <td><div align="left">
    > <input name="Submit2" type="reset" class="input"
    > value="Reset">
    > </div>
    > </tr>
    > </table>
    > <body>
    > </form>
    >

  • Updating a standard table from a custom tableq

    hi to all experts,
    My requirement is to update a standard table from the maintenance screens of the custom table whatever the data the user maintains in the custom table and save should automatically saved in the standard table
    for that i decided to use the table maintenance events (event 05 ) ( while saving data) how to capture the data from the screens to the form of the table maintenance events.

    Hi gautham,
    The requirement is like that actually user want to maintain value in z table ( with one extra field ) . the table updation of table is important

  • Validating Tabular Form Column Against Value From Another Table

    Hi,
    I am brand new to this forum, so please bear with me a little!  I only have a small amount of experience writing PL/SQL, and I've never written Javascript or JQuery before.  I am an Oracle DBA, and I have coding experience in C and PERL, so I do have a solid technical background.  But, I need some advice on the best way to approach a problem.
    I have a database application in Oracle Apex (version 4.2) with a tabular form against a table: let's say Table #1 with cols 1A, 1B, and1C.  I need to ensure that the value entered into col B isn't greater than the value of a column in another table (let's say Table #2 col 2A).  Conceptually, the amount of money available is in Table #2, and the rows of my tabular form are an act of spending money (like orders or invoices), so I need to make sure we don't spend more than we have.  Does that make sense?
    Does anyone have any advice for the best way to do this?  I'm figuring the biggest issue here might be that we have to account for people entering mutliple rows in the tabular form at one time, right?  So, if a person entered 3 orders/invoices, I need a total to make sure they didn't spend more than we have in Table #2.
    I greatly appreciate your help! 
    Best Regards,
    Laurie Baublitz

    Hi!
    You need one process of type ajax callbacks like:
    DECLARE
       l_limit nubmer;
       l_number1 number := apex_application.g_x02;
       l_returnValue VARCHAR2(200);
    BEGIN
       select A2 into l_limit from table2;
       if l_number1 > l_limit then
          l_returnValue := 'LIMIT IS NOT SO BIG';
          if l_returnValue is not null then
             --this will write l_returnValue to the buffer, and the ajax callback will receive this
            htp.p(l_returnValue);
          end if;
      end if;
    END;
    Then you need one javascript on page, code is something like:
    $('input[name=your column in tabular which is change]').live('change', function(){
       //if value of changed field differs from an empty string
       if($(this).val()!=''){
          //put target element in a var to reference it in the ajax success callback
          var num  = $('input[name=your column in tabular with value]');
          $.post('wwv_flow.show',
                 {"p_request"      : "APPLICATION_PROCESS=your ajax callback function",
                  "p_flow_id"      : $v('pFlowId'),
                  "p_flow_step_id" : $v('pFlowStepId'),
                  "p_instance"     : $v('pInstance'),
                  "x01"            : $(this).val(),
                  "x02"            : $(num).val()
                  function(data){
                     if(data !=''){
                     alert(data);
    I can not guarante that code is 100% working, if not you need to do some changes or make an example on apex.oracle.com and provide credentials here.
    Regards,
    drama9346

  • How give a data from one table to another table

    Oracle forms6i
    Hai All
    I had two table in table data base and from one table the data has to move to another table using forms
    The two tables are
    First table name temp_att from this the data has to move and the data are
    BARCODE BARDATE BARTIME Row_number
    0000000009949296 08-NOV-09 0800 1
    0000000009949296 08-NOV-09 1230 2
    0000000009949296 08-NOV-09 1245 3
    0000000009949296 08-NOV-09 1645 4
    0000000009949297 08-NOV-09 0815 1
    0000000009949297 08-NOV-09 1230 2
    0000000009949297 08-NOV-09 1300 3
    0000000009949297 08-NOV-09 1650 4
    Another table dail_att and the fields are
    barcode,bardate,intime(mintime),outtime(maxtime),intrin(nextmintime)intr,(nextmaxtime)
    Pls give some solutions to solve this problem.
    Thanks & Regards
    Srikkanth.M

    Hai
    Could pls explain me little bit clear
    I have explained my problem clearly in the last Post
    This is the requirement
    I had two table in table data base and from one table the data has to move to another table using forms
    The two tables are
    First table name temp_att from this the data has to move and the data are
    BARCODE BARDATE BARTIME Row_number
    0000000009949296 08-NOV-09 0800 1
    0000000009949296 08-NOV-09 1230 2
    0000000009949296 08-NOV-09 1245 3
    0000000009949296 08-NOV-09 1645 4
    0000000009949297 08-NOV-09 0815 1
    0000000009949297 08-NOV-09 1230 2
    0000000009949297 08-NOV-09 1300 3
    0000000009949297 08-NOV-09 1650 4
    Another table dail_att and the fields are
    barcode,bardate,intime(mintime),outtime(maxtime),intrin(nextmintime)intr,(nextmaxtime)
    Pls give some solutions to solve this problem.
    Thanks & Regards
    Srikkanth.M

  • How can i pull the value of one cell into the cell of another table?

    I want to pull the value (the result of a =SUM(x) formula as the starting value of a column in another table.  How can I do that?

    Yvan KOENIG (VALLAURIS, France) vendredi 10 février 2012
    iMac 21”5, i7, 2.8 GHz, 12 Gbytes, 1 Tbytes, mac OS X 10.6.8 and 10.7.3
    My Box account  is : http://www.box.com/s/00qnssoyeq2xvc22ra4k

Maybe you are looking for

  • Change desktop picture automatically doesn't work

    Hi I am trying to use the System Preferences Destop Picture "Change Picture automatically" every day feature. I want it to select a picture automatically at random every day from the folder I set. This does not seem to work. If I set it to "every day

  • Firefox does not open on-screen - looks like it scrolls off to the side.

    When I mouse over the Firefox icon, I can see that the window is open, but when I click on the icon, the window does not open onscreen and it fades in and out of the right side of my screen. Runninf Firefox 7.0.1, Windows 7 64-bit. Thanks

  • How to download data in Word or Excel file from webdynpro?

    Hello everybody, In my webdynpro application, I want to download my Table control data in word or excel file. Is there anyway to do this? Thanks in advance, Bhavik

  • Please consider the following

    People are getting bored of the same old iphone iPod and iPad structure you should be able to change it to fit your own personality. It would draw more attention to your product. By the way I have an iPhone 4

  • Missing Plugin

    when I try to watch a video on the Apple Site I get a missing plugin message.  I'm running all the current software on Lion 10.7.3 .  Please help me solve this problem.  I am able to view it on Firefox though which doesn't make sense.