Updating a date field witha field from another table

Hi friends
I have a table called Customer_Type with following fields
Customer_type ,Active_date, Inactive_date
regular,11/01/2011
daily,11/04/2011
monthly,11/05/2011/11/11/2011
Tbale 2:Customer
Customer_name,Customer_type,Customer_Inactive_date
John,regular,
James,monthly,
Jake,daily,
Jill,monthly
What i wnat is to update the Customer_inactive_date with the Incative_date field from Customer_type
based on their Customer_type... So james and Jill would have their rows updated in this scneario ..How can i achive this in pl/Sql
Thank you in advance...

Hi,
You can look at this code; it's not PL/SQL but a simple MERGE statement:
CREATE TABLE CUSTOMER_TYPE
  type_code VARCHAR2(10),
  active_date DATE,
  inactive_date DATE
INSERT INTO customer_type VALUES('REGULAR', TO_DATE('11/01/2011', 'DD/MM/YYYY'), null);
INSERT INTO customer_type VALUES('DAILY', TO_DATE('11/04/2011', 'DD/MM/YYYY'), null);
INSERT INTO customer_type VALUES('MONTHLY', TO_DATE('11/05/2011', 'DD/MM/YYYY'), TO_DATE('11/11/2011', 'DD/MM/YYYY'));
CREATE TABLE CUSTOMERS
  customer_name varchar2(10),
  customer_type varchar2(10),
  customer_inactive_date DATE
INSERT INTO customers VALUES('John', 'REGULAR', null);
INSERT INTO customers VALUES('James', 'MONTHLY', null);
INSERT INTO customers VALUES('Jake', 'DAILY', null);
INSERT INTO customers VALUES('Jill', 'MONTHLY', null);
MERGE INTO customers dst
USING customer_type src
ON (dst.customer_type = src.type_code)
WHEN MATCHED THEN
  UPDATE set dst.customer_inactive_date = src.inactive_date;
SELECT * FROM customers;
CUSTOMER_NAME CUSTOMER_TYPE CUSTOMER_INACTIVE_DATE   
John          REGULAR                                
James         MONTHLY       11-NOV-11                
Jake          DAILY                                  
Jill          MONTHLY       11-NOV-11                 If you don't understand it, just let me know...

Similar Messages

  • Update table with select from another table

    Hallo,
    I'd like to update table b with codes from a mapping table a.
    a has:
    town_id, town_code, town_name
    b has town_code, town_id, town_population, town_zip_code,...
    Table a has all the details - town_id, town_code and town_name and acts as the mapping between town_id and town_code
    In table b, town_code is null. I want to update the column b.town_code with town_code from table a where a.town_id = b.town_id.
    How will the update query look like?
    I tried
    UPDATE B SET town_code = (SELECT A.town_code FROM A,B WHERE A.town_id=B.town_id)
    and I get the error 'single-row subquery returns more than one row'
    Will appreciate your assistance

    This is what I did.
    First, I created and populated the TOWN_INFO table:
    CREATE TABLE "TOWN_INFO"
    (     "TOWN_ID" NUMBER,
         "TOWN_CODE" NUMBER,
         "E_MAIL" CHAR(15 BYTE)
    Table Created.
    insert all
    into TOWN_INFO (TOWN_ID, E_MAIL) values (3024,'[email protected]')
    into TOWN_INFO (TOWN_ID, E_MAIL) values (3040,'[email protected]')
    into TOWN_INFO (TOWN_ID, E_MAIL) values (3052,'[email protected]')
    into TOWN_INFO (TOWN_ID, E_MAIL) values (3065,'[email protected]')
    into TOWN_INFO (TOWN_ID, E_MAIL) values (3066,'[email protected]')
    select * from dual
    5 rows created.
    The following creates and populates the mapping table:
    CREATE TABLE "TOWN_MAPP"
    (     "TOWN_CODE" NUMBER,
         "TOWN_ID" VARCHAR2(255 BYTE),
         "TOWN_NAME" CHAR(6 BYTE)
    insert all
    into TOWN_MAPP (TOWN_ID,TOWN_CODE, TOWN_NAME) values (3024,'1001','TOWN_1')
    into TOWN_MAPP (TOWN_ID,TOWN_CODE, TOWN_NAME) values (3040,'1003','TOWN_3')
    into TOWN_MAPP (TOWN_ID,TOWN_CODE, TOWN_NAME) values (3052,'1002','TOWN_2')
    into TOWN_MAPP (TOWN_ID,TOWN_CODE, TOWN_NAME) values (3065,'1004','TOWN_4')
    into TOWN_MAPP (TOWN_ID,TOWN_CODE, TOWN_NAME) values (3066,'1006','TOWN_6')
    into TOWN_MAPP (TOWN_ID,TOWN_CODE, TOWN_NAME) values (3088,'1007','TOWN_7')
    into TOWN_MAPP (TOWN_ID,TOWN_CODE, TOWN_NAME) values (3020,'1009','TOWN_9')
    select * from dual
    7 rows created.
    And now the update query:
    UPDATE TOWN_INFO
    SET TOWN_CODE=(SELECT B.TOWN_CODE FROM TOWN_MAPP B, TOWN_INFO C
    WHERE B.TOWN_ID=B.TOWN_ID)
    SET TOWN_CODE=(SELECT B.TOWN_CODE FROM TOWN_MAPP B, TOWN_INFO C
    ERROR at line 2:
    ORA-01427: single-row subquery returns more than one row
    Thanx in advance
    Edited by: user9954260 on Apr 13, 2010 7:40 AM
    Edited by: user9954260 on Apr 13, 2010 7:44 AM

  • How to update this table with values from another table ?

    Hi
    I have a table "regies". I want to replace the values of the column "regies.agent" by the value of the column "regies_personnes.id"
    As you see the tables have a common values column. ie regies.agent = regies_personnes.nom
    Table "regies" :
    Insert into "regies" (AGENT) values ('Humberdot Alain');
    Insert into "regies" (AGENT) values ('Danard Patrick');
    Table "regies_personnes" :
    Insert into REGIES_PERSONNES (NOM,ID) values ('Humberdot Alain',1);
    Insert into REGIES_PERSONNES (NOM,ID) values ('Danard Patrick',2);
    Before we have this
    sql>select agent from regies ;
    Humberdot Alain
    Danard Patrick
    After the update, the result should be
    sql>select agent from regies ;
    1
    2
    Thank you for your kind answer.

    You will face error if you have duplicates
    ORA-01427 Single row subquery returns Multiple rows.Try this way
    create table regies(agent varchar2(30));
    create table regies_personnes( nom varchar2(30),id number);
    Insert into regies (AGENT) values ('Humberdot Alain');
    Insert into regies (AGENT) values ('Danard Patrick');
    Insert into REGIES_PERSONNES (NOM,ID) values ('Humberdot Alain',1);
    Insert into REGIES_PERSONNES (NOM,ID) values ('Danard Patrick',2);
    Insert into regies (AGENT) values ('Humberdot Alain');
    Insert into regies (AGENT) values ('Danard Patrick');
    Insert into REGIES_PERSONNES (NOM,ID) values ('Humberdot Alain',1);
    Insert into REGIES_PERSONNES (NOM,ID) values ('Danard Patrick',2);
    commit;
    update regies r set agent = (select id from regies_personnes p where r.agent = p.nom
    and rownum=1)
      where exists (select id from regies_personnes p where r.agent = p.nom
    commit

  • UPDATING A TABLE WITH SAME INFO FROM ANOTHER TABLE ON THE SAME DB

    0down votefavorite
    I am trying to update a table with info from another table on the same db with same table name. I just want the info to be the same , no primary key or constraint involve just a straight replacement of records and I keep getting errors WITH THE TABLE not
    being recignize. below is my query:
    UPDATE
    VNDFIL
    SET EOBTYP
    =  VNDFIL.EOBTYP, 
    EDI_X12_835_VERSION =  VNDFIL.EDI_X12_835_VERSION
    FROM
    AGERECOVERY
    WHERE
    VNDFIL.EOBTYP
    = VNDFIL.EOBTYP
    AND
    VNDFIL
    .EDI_X12_835_VERSION
    = VNDFIL.EDI_X12_835_VERSION

    Hi rotary,
    If those two same named tables are in the same database then they have to be in different schemas. If you mean they are in the same server instance, then they may be in different databases, besides the "table not being recognized" error,
    anyway you should use the fully qualified table names, that is database.Schema.Table(If across instances, ServerName should be prefixed) to avoid the table unrecognized error.
    Using Identifiers As Object Names
    With the fully qualified names, your update statement can be like below.
    UPDATE
    db1.schema1.VNDFIL
    SET EOBTYP = srcTbl.EOBTYP, EDI_X12_835_VERSION = srcTbl.EDI_X12_835_VERSION
    FROM
    db1.schema2.VNDFIL srcTbl
    WHERE
    db1.schema1.VNDFIL.EOBTYP = srcTbl.VNDFIL.EOBTYP AND
    db1.schema1.VNDFIL.EDI_X12_835_VERSION = srcTbl.VNDFIL.EDI_X12_835_VERSION
    If you have any question, feel free to let me know.
    Eric Zhang
    TechNet Community Support

  • Form item from another table

    I want to create a form that inserts rows in a table'mstr';
    when inserting a row I want to have a field populated with
    information from another table 'dept', where the department
    in 'mstr' equals the dept in 'dept' table. How?

    Write a database trigger to populate it.

  • Breakout table (fill table with matching data from another table)

    Hi
    I've been trying to study old discussions about breakout tables. I feel I'm close, but still no cigar :-)
    In plain english, I'm trying to autocreate rows with data on a table, based on matching values from another table. E.g. have a table to display all rows where type = AssetX
    I have attached a screenshot of my "master table" called Assets:
    I'm looking to prefill Asset name, Total from this table and populate a new table called e.g. Greenhouse
    Where I'd be adding more data (date, income, expense).
    Any help whould be greatly appreciated.
    Thanks!

    Hi,
    Here is a Sample Query.
    Update Emp A
    Set Sal = (Select Sal from emp b where
    a.empno = b.empno)
    where empno in (select empno from emp);
    Regards,
    Ganesh R
    null

  • UPDATE SQL string substitution from another table

    Hi - I've come across a tricky situation where I would want to update a column in all the relevant rows of a table with values obtained from another table WITHIN the same column update using string concatenation. im not getting any clean way of doing this.
    The goal is to achieve something like this:
    UPDATE table1 set col1 =
    'LANG_ID=(%s),'||
    '_CHALLENGE_RESPONSE_=(%s),'||
    'CRDN_NAM=(%s),'||
    'CLNT_MODE=(%s),'||
    'PTY_ID=(%s),'||
    'CRDN_VAL=(%s),' ||
    'USER_TZ_COD=(%s),' ||
    'GTS_USER_ID=(%s),'||
    'SP_ID=(%s),' ||
    'SP_ALIAS=(%s),' ||
    'ORIG_CLNT_ID=(%s)'
    where table1.col1 is null
    and to substitute the (%s) with data from another table2*. An example is:
    update table1 set col1=
    'LANG_ID=(select LANG_ID from table2* where USER_ID = (select USER_ID from table1))' ||
    '_CHALLENGE_RESPONSE_=((select CHALLENGERESPONSE_ from table2* where USER_id = (select USER_ID from table1)),' ||
    etc for the rest of the values

    I tried this -although the database shows that the affected rows are updated! but querying the table doesn't show the values in the column!
    select col1 from table1 where col1 is null
    shows back the original content (DESPITE it showing me xxx rows updated!)
    UPDATE table1 t1
    SET col1 = (SELECT 'LANG_ID=('||lang_id||')_CHALLENGE_RESPONSE_=('||
    CHALLENGERESPONSE_|| ...*
    FROM table2 t2
    WHERE t1.user_id = t2.user_id)
    WHERE t1.col1 is null;

  • Data from another table, to be displayed on table based screen

    I have a block that is based on one table, if I found the record(s) on that table I will display it on the forms, No Problemo. But, if record(s) was not in the said table, I have to get the data on another table and then display it on the same forms. Is there someone who can show me how I can get the data from another table and display it on screen that is based on another table?

    suppose you have 2 table emp_n and emp with same table structure
    first check data from emp_n if not found then go to emp
    try it:-
    you will change block name at run time(query data source)
    by
    emp_n is old
    emp is new
    set_block_property('emp_n',QUERY_DATA_SOURCE_NAME,'emp');
    if no data found in emp_n table then
    change the block query name by
    set_block_property('emp_n',QUERY_DATA_SOURCE_NAME,'emp');
    in next try it will go to emp table for fetching record
    kuljeet pal singh

  • Can I update a blog created in iWeb from another computer?

    Hello Forum,
    While I am away from my office base, I would like to update my blog (created using iWeb) from another computer. I have a dotmac account.
    I thought doing this should pose no problems, but I simply can't figure it out.....
    Hope someone can help me out on this one.
    Many thanks in advance,
    Greg

    When you go to .mac and log in, you should see stories there regarding the features of .mac. One of the recent ones (should still be on the front page) is Tech note: Using iWeb on more than one Mac
    Underneath this header, you'll find
    "All you need to do is quit iWeb (if it’s open), locate the domain.sites file (Users/<username>/Library/Application Support/iWeb/domain.sites), and move it to wherever you’re going to use it. Then double-click the file in its new location. iWeb will launch, and you’re done. From then on, iWeb will automatically save your work in the new location, and you’ll be able to publish your site from any Mac that has access to it.
    So, if your domain.sites is small enough to fit on your iDisk, you could keep a copy there and use it from any computer that has iWeb 1.1 or later installed to update your blog.

  • HT4356 can i airprint to my airprint printer remotely, with ipad, from another wifi connection or only when i am within my own network?

    can i airprint to my airprint printer remotely, with ipad, from another wifi connection or only when i am within my own network?

    Air print, and the normal hp airprint set up requires that the pad and the printer be on the same wifi net work.  The 'connecting' is done by your router.  That means remote printing wont work with the out of the box stuff.  I think you might find some 3rd party apps that do support remote  printing, but i have not seen any reports from users that found a really good solution.  Print n share reads like it might work, i am sure some users will chime in.

  • Looping delete statement where table name is coming from another table

    Hi All,
    We have to write code to delete records from active tables of WDSO.We have 5 DSO  so inspite of writing delete statement for each table we want to put all table names into one table and then loop through it .but we are getting error when we are refering that table field which has active table name.error is :
    "dictionary structure or table is either not active or does not exist "
    As per my understanding in a delete /select /insert /update statement we need to put table name (whose field we are refering ) it can't be replaced by a variable .
    ex: v_table = 'EMPLOYEE' .
    DELETE FROMv_table WHERE EMP_NAME = 'ABDC' .
    is wrong and it must be like
    ex : DELETE FROM EMPLOYEE WHERE EMP_NAME = 'ABDC' .
    but we want to make our code dynamic .
    Can you please suggest a way so that we can read the table names from another table and delete data based on some selection fom those tables .
    I tried variants ,perform etc and even searched FM for the same but not found a solution .Your help will be greatly appreciated .
    Thanks in advance .
    Regards,
    Jaya

    Hi,
    You can change your statement as follows:
    DELETE FROM (v_table) WHERE EMP_NAME = 'ABDC' .
    However, I would not recommend this. There is a standard function module RSAN_ODS_DATA_DELETE which allows selective deletion - that should be a safer way to do this. You can

  • FETCHING VALUES IN MULTI RECORD BLOCK FROM ANOTHER TABLE USING SELECT STATEMENT.

    Hi,
    I have one multi record block in which i want to fetch values
    (more then one record) from another table using select statement
    IN KEY NEXT ITEM.I am getting following error.
    ORA-01422: exact fetch returns more than requested number of rows
    Thanks in advance.

    In your case I see no reason to use non-database block and to try to populate it from a trigger with a query, instead of using the default forms functionality where you can associate the block and the fields with table, create where clause using bind variables and simply use execute_query() build-in to populate the block. The power of the forms is to use their build-in functionality to interact with the database.
    Also, you can base your block on a query, not on a table and you dynamically change this query using set_block_property() build-in. You can use any dynamic queries (based on different data sources) and you simply need to control the column's data type, the number of the columns and their aliases. Something like creating inline views as a block data source.
    However, you can replace the explicit cursor with implicit one like
    go_block('non_db_block_name');
    first_record();
    FOR v_tab IN (SELECT *
    FROM tab
    WHERE col_name = :variable)
    LOOP
    :non_db_block_name.field1 := v_tab.col1;
    :non_db_block_name.field2 := v_tab.col2;
    next_record();
    END LOOP;

  • Getting description of product from another table

    Hi,
    I am getting the level from the user, and based on that creating an internal table.  I am getting product code (PRODH) and level (STUFE) from one table (T179), and getting product description (VTEXT) from another table (T179T).  I need to create a single internal table (PVS) with all three fields.
    How do I do that?  This may seem like a very simple question, but I have only been teaching myslef ABAP for about one week.
    Once I can prepare this table, I will use a function to display it.
    Regards,
    Al Lal
    Code:
    REPORT  YABHINAV16.
    program to display products at chosen level *
    Tables: T179, T179t.
    types:  begin of hierarchy,
            prodh type t179-prodh,
            vtext type t179t-vtext,
            stufe type t179-stufe,
            end of hierarchy.
    data: pvs type standard table of hierarchy initial size 0.
    select-options level for t179-stufe no intervals.
    Select prodh stufe from T179 into corresponding fields of table pvs where stufe in level.
    select vtext from t179t into corresponding fields of table pvs where prodh = pvs-prodh.
    sort pvs by prodh.

    Hi Just change the code accordingly...
    Tables: T179, T179t.
    types: begin of hierarchy,
    prodh type t179-prodh,
    vtext type t179t-vtext,
    stufe type t179-stufe,
    end of hierarchy.
    types: begin of text,
             prodh type t179t-prodh,
             vtext type  t179t-vtext,
             end fo text.
    data: pvs type standard table of hierarchy initial size 0.
    data: it_text type standard table of text,
            wa_text type text.
    select-options level for t179-stufe no intervals.
    start-of-selection.
    Select prodh stufe from T179 into corresponding fields of table pvs where stufe in level.
    select prodh vtext from t179t into corresponding fields of table text for all entries in pvs where prodh = pvs-prodh.
    end-of-selection.
    sort pvs by prodh.
    sort it_text by prodh.
    loop at pvs.
    read table it_text into wa_text with key prodh = pvs-prodh.
    if sy-subrc eq 0.
    pvs-vtext = wa_text-text.
    endif.
    modify pvs.
    endloop.
    Award Points If useful

  • How to populate a table based on a row selection from another table.

    Hi, i just started to use ADF BC and Faces. Could some one help me or point me a solution on the following scenario .
    By using a search component , a table is being displayed as a search result. If i select any row in the resulted table , i need to populate an another table at the bottom of the same page from another view. These two tables are related by primary key . May i know how to populate a table based on a row selection from another table. Thanks
    ganesh

    I understand your requirement and the tutorial doesn't talk about Association between the views so that you can create a Master-Detail or in DB parlance, a Parent-Child relationship.
    I will assume that we are dealing with two entities here: Department and Employees where a particular Department has many Employees and hence a Parent-Child relationship.
    Firstly, you need to create an Association between the two Entities - Department and Employees. You can do that by right clicking on the model's entity and then associating the two entities with the appropriate key say, DepartmentId.
    Once you have done that, you need to link the two entities in the View section with this Association that you created. Then go to AppModule and make sure that in the Available View Objects: 'EmployeesView' appears under 'DepartmentView' as "EmployeesView via <link you created>". Shuttle the 'DepartmentView' to the right, Data Model and then shuttle
    "EmployeesView via <link you created>" to the right, Data Model under 'DepartmentView'.
    This will then be reflected in your Data Controls. After that, you simply would have to drag this View into your page as a Master-Detail form...and then when you run this page, any row selected in the Master table, would display the data in the Detail table.
    Also, refer to this link: [Master-Detail|http://baigsorcl.blogspot.com/2010/03/creating-master-detail-form-in-adf.html]
    Hope this helps.

  • Default value from another table - sql query

    I'm trying to make the default value of a text item as the result from an sql or pl/sql statement. I keep getting errors when I try to use a pl/sql statement to do this. Has anyone else done this?

    OK, here is what I tried to put in. I have a form and I wanted to add a text field that is derived from another table, such as:
    select question from qa_main where seq=:quest_num
    So, what I want is to have a form where questions on tests are answered, and I want the text of the question to be brought over from the question table. I'm not sure if I'm using the correct syntax, but the ":quest_num" would be a reference to a question number in the answer table that is linked to the sequence number (primary key) in the questions table.
    Of course if there are better ideas, please let me know. :)

  • Column names from another table

    Hi All,
    I have a scenario where i need to get names of a column from another table
    for eg,
    Table EMP
    EmpNo EmpName EmpContact EmpPhone
    1 xyz [email protected] 345     
    2 abc [email protected] 897
    3 ttp [email protected] 345
    The column names of this table can be configurable from some other place and its value is stored in another table like
    Table Config (2 Columns)
    Column_Name Value
    EmpName First name
    EmpContact Email
    EmpPhone Mobile
    Now i want to fetch the values from Emp table but with column headers that are changed and have a value in Config table.
    If a column name is not there in config table then the original column name should come.
    As shown below
    EmpNo First name Email Mobile
    1 xyz [email protected] 345
    2 abc     [email protected] 897
    3 ttp [email protected] 345
    Another eg, If EmpName is not changed and entered in second table , then i want to have the same name as the original EMP table has as shown below.
    EmpNo EmpName Email Mobile
    1 xyz [email protected] 345
    2 abc     [email protected] 897
    3 ttp [email protected] 345
    In other words something like this,
    select empno,
    EmpName as (select value from config where column_name=EmpName),
                   EmpContact as (select value from config where column_name=Empcontact),
                   EmpPhone as (select value from config where column_name=EmpPhone)
         From EMP
    Can some one please help me in providing a solution for this.
    Edited by: 941386 on May 30, 2013 6:20 AM

    Unfortunately, I think this is a job for dynamic sql ...
    Build your "query" first:
    (note this won't work "as is", fix the syntax - but you get the idea.)
    lv_str := 'select empno,
    EmpName as ' || (select value from config where column_name=EmpName) || ',
    EmpContact as ' || (select value from config where column_name=Empcontact) || ',
    EmpPhone as ' || (select value from config where column_name=EmpPhone) || '
    From EMP;';
    execute immediate lv_str;Not sure if there's a better way or not.
    Only other way I can think of is to leverage the way UNION [ALL] works.
    So the following query:
    select a, b, c from dual
    union all
    select d, e, f from dual
    /returns data in columns "named" : "a, b, c"
    Effectively renaming columns d, e, f. You just need to turn your data on edge in that first query, then throw out the rows (I don't know how to get it to work, but perhaps somebody else does?)
    [edit]
    another thought is create a view over top of the table, query that view, then drop the view :P
    that would work nicely - avoid the dynamic SQL. shrug
    [edit]
    Edited by: Greg.Spall on May 30, 2013 9:37 AM

Maybe you are looking for

  • Constant failures in setting up scalable wordpress. Update ClearDB database failed.

    I've been having Constant failures in setting up scalable wordpress with no luck on finding a fix.  Update ClearDB database failed is the most common issue, with Update deployment being the second issue. I though maybe it had to do with Azure changes

  • Invitees notified even after delete their names!!

    My current setup includes two calendar's for each subject. For example, I have a separate one for BILLS DUE and a separate one (grey color so it doesn't stand-out as much) for BILLS DONE. When I have a pending bill due in the future, I set it to BILL

  • Error message on Merge to HDR

    Hi - Whenever I use the Merge to HDR function (CS4, using XP, SP3) I get a strange error message at the end of the processing portion (just before the completed 32-bit image displays).  The error says something to the effect that it's possible that t

  • With iPhoto '11, can I access an actual jpg image from somewhere?

    I want to be able to make sure I can backup the actual, original, jpg image that is imported into iPhoto. Is there anyway to do this? Or how do I find the folder which contains the actual jpg files of the images I import into iPhoto? I am concerned w

  • WSUS Drivers Best Practices

    Hello, I am configuring WSUS on our network (Server 2012), and have a couple concerns regarding Driver updates. I would like the machines connected be able to update their drivers when necessary. It is important to note that for the Update Files and