UPDATE value in column with value in SAME TABLE

Hi all,
Here's my issue...
I have a table which records all incidents for a person.
The table looks something like this:
tbl_connect(person_Id NUMBer,
OLD_ID VARCHAR2(24),
CASE_NUMBER     VARCHAR2(10),
CASE_TYPE     VARCHAR2(10),
PERSON_ROLE     VARCHAR2(30),
INCIDENT_TYPE     VARCHAR2(40));
The table is populated from a source table with all fields except person_id. Person_id is a sequence number that gets generated if the person comitting the incident is a NEW PERSON to our system. OLD_Id is the unique identifier between the source table and tbl_connect to identify a person.
The problem: If an existing person commits a new incident, a new record will be inserted into tbl_connect without PERSON_ID. Since the person already is in the database the person_id already exists in tbl_connect for that person. I now need to UPDATE person_id column with the person_id that already exists for this person. How can i achieve this.
Ive been trying all sorts of update queries but nothing seems to work. ANy help will be appreciated. Thanks in advance.

Frank,
Thanks for the speedy reply. Here is a sample table.
I know it's a bit confusing. The data that is being dumped into this table is information from a old system. The OLD_ID is in here because it is the relationship between this table and the old table. PERSON_ID is new to this system to identify a person uniquely. That is why i need them both in this table for right now.
So say my tbl_connect got populated with new info from the old table. As you can see, old_id=567A has comitted another incident. Since he already exists in tbl_connect, now i need to update person_id with the value of 1. Does that make sense now????? If old_id did not exist, all i would do is insert a new row and set person_id to the next sequence number.
TBL_CONNECT
PERSON_ID OLD_ID      CASE_NUMBER CASE_TYPE          
1     567A     12345          IR          
1     567A     15236          MV
     567A     98547          IR<--newly inserted record of same person

Similar Messages

  • Report with multiple COUNT columns with counts from same table

    I am new to discoverer so I am a bit lost.
    I am working to create a report to show usage data from the eBusiness Knowledge Base. I have the query written in SQL using subqueries that is in the format:
    Solution Number | Soultion Title | Solution Views | Positive Feedback | Negative Feedback
    12345 ___________ Title ________ 345 ____________ 98 _______________ 34
    The 'Views', 'Positive' and 'Negative' entries are stored in the same table so i am doing a count where setid=setid and usedtype=VS, then counting where usedtype=PF and usedtype=NF
    In discoverer I can get the solution number, title and ONE of the totals but I can't seem to figure out how to get a COUNT for three different things from the same table in columns on the same row.
    When I go to edit sheet -> select items once I select the COUNT option for the UsedType column in the table CS_KB_SET_USED_HISTS I can't select it again. I also have found now way to add a column based on an entered query.
    If anyone could help it would be much appreciated.
    Thanks
    Edited by: Toolman21 on Dec 2, 2010 2:17 PM
    added ______ to correct spacing.

    Hi,
    You can separate the column by using a case or decode.
    for example create 2 calculations:
    case
    when usedtype='PF'
    then <you original column> --- the one contain them both
    else 0
    end
    case
    when usedtype='NF'
    then <you original column> --- the one contain them both
    else 0
    end
    after that you can create the count aggregation over those.
    Tamir

  • Updating values with in the same table for other records matching conditions

    Hi Experts,
    Sorry for not providing the table structure(this is simple structure)
    I have a requirement where i need to update the columns of a table based on values of the same table with some empid and date  match. If the date and empid match then i have take these values from other record and update the one which is not having office details. I need the update query
    Before update my table values are as below
    Sort_num     Emp_id   office      start_date
    1                      101     AUS    01/01/2013
    2                      101                01/01/2013
    3                      101               15/01/2013
    4                      103     USA    05/01/2013
    5                      103               01/01/2013
    6                      103                05/01/2013
    7                      104     FRA    10/01/2013
    8                      104               10/01/2013
    9                      104                01/01/2013
    After update my table should be like below
    Sort_num     Emp_id   office      start_date
    1                      101     AUS    01/01/2013
    2                      101     AUS    01/01/2013
    3                      101               15/01/2013
    4                      103     USA    05/01/2013
    5                      103               01/01/2013
    6                      103    USA     05/01/2013
    7                      104     FRA    10/01/2013
    8                      104     FRA     10/01/2013
    9                      104                01/01/2013
    Thanks in advance

    I do not have time to create the table with data but basically you should be able to code the following
    update table a
    set office = ( select office from table b where b.emp_id = a.emp_id
                                                                 and     b.start_date = a.start_date
                                                                 and     b.office is not null
    where exists ( [same query as in set]  )
    and a.office is null
    I believe that will do the trick.
    HTH -- Mark D Powell --

  • Update A Column with value of Column in the next Row

    Hi All,
    I have a table which is like this
    ID NUMBER,
    SUB_ID NUMBER,
    STARTDATE DATE.
    The Value is say for example like this:
    ID     SUB_ID     StartDate
    1     1     1-JAN-09
    1     2     20-FEB-09
    1     3     1-MAR-09
    2     1     10-JAN-09
    2     4     10-APR-09
    2     3     1-MAR-09
    2     2     2-FEB-09
    I have to add a new column END DATE in the table and populate a value which is One Day less than the value of
    start Date for next row. I have to order by ID and SubID and so that colum looks like this.
    ID     SUB_ID     StartDate          END DATE
    1     1     1-JAN-09          19-FEB-09
    1     2     20-FEB-09          28-FEB-09
    1     3     1-MAR-09          DEFAULT-END DATE
    2     1     10-JAN-09          1-FEB-09
    2     2     2-FEB-09          8-Mar-09
    2     3     9-MAR-09          9-APR-09     
    2     4     10-APR-09          DEFAULT END DATE
    Can this be achieved using a single update query or I have ot write a Procedure ...any help will be appreicaited

    or
    merge into test
    using (select rowid rid
                , id
                , sub_id
                , startdate
                , lead (startdate) over (order by id, sub_id) - 1 ed
           from test) x
    on (x.rid = test.rowid)
    when matched then
       update set end_date = x.ed
    ;

  • Update a column with value of column of other table

    Hi,
    I am looking for an update statement for the following scenario
    With following 2 tables
    TABLE1 (Primary A, B)
    TABLE2 (Secondary C , D).
    C Column is not unique.
    Please provide me an update statement to update TABLE1.B with TABLE2.D where TABLE1. A = TABLE2.C
    Please note that TABLE2.C is not unique.
    Please let me know whether this satement is correct.
    UPDATE TABLE1
    SET B = (SELECT DISTINCT D FROM TABLE 2 WHERE A=C )
    Thanks
    Alla Kishore

    UPDATE TABLE1 T1
    SET T1.B = (SELECT DISTINCT D FROM TABLE2 T2 WHERE T2.C=T1.A )

  • How to pass prompt value to columns with formula?

    Hello guys
    I have a situation:
    I have a report with 1 column name 'product' and in this column it has a case statement like 'case when item is ('a','b','c','d') then 'Men' else 'women' end'
    Then I have created a dashboard prompt of the exact same column, and I defined the same case statement in the prompt's column formula as the same.. Then I tested the prompt and it is returning only 2 values 'men', 'women'..
    However, when putting the prompt and report on the same dashboard, the report is not accepting the prompt values..
    Then I set the presentation variable on the prompt and call it 'Product', then in the report I created a filter on 'product' column as equal to presentation variable 'product'--- I tried with and without single quotes.. So the filter itself looks like : case when ...... is equal to / is in @{product}
    However, when I then return back to the dashboard, I am getting the error:
    State: HY000. Code: 388918336. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 27005] Unresolved column: "Product". (HY000)
    Could anyone help?
    Thanks

    Hola
    is possible that are you using a BINS agrupation into the Column Formula?
    if you form a CASE statement using a Bins agrupation, in the column Formula, this must be disabled to match statements between columns and DB Prompt
    if you are using a BINS agrupation to form the CASE statement, you have to delete the bins agrupation in the Column but keep the CASE statement
    Regards

  • Create values for analogous periods in the same table with DS

    Hi,
    in the course of a pilot we want to create additional columns with data for analogous periods.
    We have values for a month and need to create new columns for values for last month and last year in order to compare.
    Attached youu2019ll find a few sample rows resembling the basic concept of what we have
    Region     Country     Year     Month     Value
    Europe     Spain     2009     1     285
    Europe     Spain     2009     2     129
    Europe     Spain     2009     3     153
    Europe     Spain     2008     1     288
    Europe     Spain     2008     2     284
    Europe     Spain     2008     3     125
    Europe     France     2009     1     135
    Europe     France     2009     2     125
    Europe     France     2009     3     284
    Europe     France     2008     1     208
    Europe     France     2008     2     221
    Europe     France     2008     3     220
    In this case, new columns would be
    LastMonth (125 for Spain month 1 year 2009, since this is the value for month 3 year 2008)
    LastYear (288 for Spain month 1 year 2009, since this is the value for month 1 year 2008).
    Can you help on what function to use in the DS query transformation?
    thanks everybody, and enjoy!

    Hi David,
    Probably the easiest way of resolving this would be to add extra columns which show the projected date each row should be shown on e.g.
    Region     Country     Year     Month     Value     LM_Year     LM_Month     LY_Year     LY_Month
    Europe     France     2008     1     208     2008     2     2009     1
    Europe     France     2008     2     221     2008     3     2009     2
    Europe     France     2008     3     220     2008     4     2009     3
    Europe     France     2009     1     135     2009     2     2010     1
    Europe     France     2009     2     125     2009     3     2010     2
    Europe     France     2009     3     284     2009     4     2010     3
    This would be written to a staging table then used as a source with the original source file to produce the target table. I've illustrated an example of how this could be achieved below:
    Create two dataflows; DF 1 and 2.
    In DF 1 read source, add additional columns to show the date (year, month, etc) this should be projected as. This would need to be done for both the last month and last year. Load staging table.
    In DF 2 Read the source and outer join to the new staging table twice. Use the region, Country, Year, Month, to join and use the new additional projected date columns. Ensure the last month date fields are used on one staging table and last year date fields are used on the next staging table. The value from the two staging tables is then used in the last month and last year value.
    Load into target table.
    To calculate the projected date columns you would probably want to format the source fields into a date then add the required number of months. e.g. to_date('01' || month || year, 'DDMMYYYY') + 12
    Obviously this would need the stage table to be truncated before each load and you would need to assess your load strategy. When doing these calculated fields if you have any retrospective updates on the source then these would then need recalculating, therefore this assumes it's a complete reload each time.
    Edited by: Richard Saltern on Jul 16, 2010 2:01 PM
    Edited by: Richard Saltern on Jul 19, 2010 10:10 AM

  • Concatenation of character values by columns with excluding duplicates

    Hi all! Assume, that there is a multi-rows table of the following form (for example):
    1|A  |   |B  |C  |   |D  |   |
    2|   |   |A  |B  |C  |D  |   |
    3|   |A  |B  |   |   |C  |D  |
    4|   |   |A  |   |B  |C  |D  |
    5|   |   |A  |   |B  |   |C  |i.e. there are NULL and NOTNULL values in VARCHAR2( or NVARCHAR2) format, and the first column is a primary key.
    I need to do next:
    1. Select some set of certain rows, primary keys of those are initialy known, e.g. 1, 3, 5;
    2. Parse this table such way: concatenate values by columns in selected rows, if there are few not-null values in one column, it's necessary to separate concatenated values with comma and whitesbase (it's desirable that's word after comma with whitespace is outputted in lowercase). Finally, it's necessary to insert dot and whitespace character after the last value.
    3. Exclude duplicate substrings from the outcoming text values.
    Thereafter I need to initialize set of local variables with the values, obtained by forementioned parsing (parsing of one column match the corresponding variable), e.g. columns of 1, 3 and 5 rows.
    I.e. result in our case looks like:
    variable1 = A.
    variable2 = A.
    variable3 = B, A.
    variable4 = C.
    variable5 = B.
    variable6 = D, C.
    variable7 = D, C.
    Does the task will be easier, if the number of parsed rows is known (e.g. 3 as in our case)?
    Edited by: 942736 on 02.10.2012 17:17

    You missed your db-version. Please give the result from
    select * from v$version;When you are on 11.2 you can try this (will not work with 10.x):
    with yourtable as
    select 1 id, 'A' col1, 'N' col2, 'B' col3, 'C' col4 ,'N' col5, 'D' col6 ,'N' col7 from dual union all
    select 2,'N','N','A','B','C','D','N' from dual union all
    select 3,'N','A','B','N','N','C','D' from dual union all
    select 4,'N','N','A','N','B','C','D' from dual union all
    select 5,'N','N','A','N','B','N','C' from dual
    select
    (select listagg(col1,',') within group (order by id)||'.' from (select distinct col1, min(id) over (partition by col1 order by id) id from yourtable where id in (1,3,5))) v1,
    (select listagg(col2,',') within group (order by id)||'.' from (select distinct col2, min(id) over (partition by col2 order by id) id from yourtable where id in (1,3,5))) v2,
    (select listagg(col3,',') within group (order by id)||'.' from (select distinct col3, min(id) over (partition by col3 order by id) id from yourtable where id in (1,3,5))) v3,
    (select listagg(col4,',') within group (order by id)||'.' from (select distinct col4, min(id) over (partition by col4 order by id) id from yourtable where id in (1,3,5))) v4,
    (select listagg(col5,',') within group (order by id)||'.' from (select distinct col5, min(id) over (partition by col5 order by id) id from yourtable where id in (1,3,5))) v5,
    (select listagg(col6,',') within group (order by id)||'.' from (select distinct col6, min(id) over (partition by col6 order by id) id from yourtable where id in (1,3,5))) v6,
    (select listagg(col7,',') within group (order by id)||'.' from (select distinct col7, min(id) over (partition by col7 order by id) id from yourtable where id in (1,3,5))) v7
    from dual;Output with 11.2 is:
    V1      V2      V3      V4      V5      V6      V7
    A,N.     N,A.     B,A.     C,N.     N,B.     D,C,N.     N,D,C.@ranit B: You missed, that the OP said that only rows 1,3 and 5 shall be used.
    Edited by: hm on 01.10.2012 23:09

  • How can I update a Site Column with the content of an array with javascript CSOM?

    I'm relative new to Sharepoint 2013, I'm trying to update the content of a Site column with the content of an array, I can retrieve and visualize the content of my site column, the user is able to change and save the necessary part and the changes are
    saved into an array, now I have to update the content of the site column with the content of the array, but for some kind of reasons I can't accomplish that, any suggestion/example? This is my code so far to retrieve, visualize the site column and store the
    mofication into my array.
        <body>
                <select id="dropdown" name="dropdown" onchange="optSelect()">
                    <option value="EngineType_Cylinders">EngineType_Cylinders</option>
                    <option value="EngineType_EngineCycle">EngineType_EngineCycle</option>
                    <option value="EngineType_EngineFamily">EngineType_EngineFamily</option>
                    <option value="EngineType_Euro">EngineType_Euro</option>
                    <option value="EngineType_FamilyEvolution">EngineType_FamilyEvolution</option>
                    <option value="EngineType_GasEmissionLevel">EngineType_GasEmissionLevel</option>
                    <option value="EngineType_Power">EngineType_Power</option>
                    <option value="EngineType_PowerSupply">EngineType_PowerSupply</option>
                    <option value="EngineType_Use">EngineType_Use</option>
                </select><br />
                <textarea id="textareadisplay" rows="25" cols="23"></textarea><br />
                <input type ="button" value="Update values" onclick="addItemsToColumns()" />
            </body>
    My Javascript
        $(function () {
            SP.SOD.executeOrDelayUntilScriptLoaded(Function.createDelegate(this, function () {
               var select = document.getElementById('dropdown').value;
                console.log(select);
                getSiteColumns(select);
            }), 'SP.js');
        var fieldChoice;
        var choices;
        var addFields = [];
        var slc;
        var clientContext;
        function optSelect() {
            slc = document.getElementById('dropdown').value;
            getSiteColumns(slc);
        function getSiteColumns(selection) {
           clientContext = SP.ClientContext.get_current();
            if (clientContext != undefined && clientContext != null) {
                var web = clientContext.get_web();
                fieldChoice = clientContext.castTo(web.get_availableFields().getByTitle(selection), SP.FieldChoice);
                clientContext.load(this.fieldChoice);
                clientContext.executeQueryAsync(Function.createDelegate(this, this.OnLoadSuccess), Function.createDelegate(this, this.OnLoadFailed));
        function OnLoadSuccess(sender, args) {
            choices = fieldChoice.get_choices();
            var textarea = document.getElementById("textareadisplay");
            textarea.value = choices.join("\n");
        function OnLoadFailed(sender, args) {
            alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
        function addItemsToColumns() {
            clientC = SP.ClientContext.get_current();
            var arrayForUpdate = $('#textareadisplay').val().split('\n');
            fieldChoice.set_item(, arrayForUpdate);
            fieldChoice.update();
            clientContext.executeQueryAsync(function () { }, function () { });
        function OnUpdateSuccess(sender, args) {
            var newchoices = fieldChoice.get_choices();
    My problem is on the function addItemsToColumns() please help! Thanks in advance.

    Let's look at your stylesheet -
    <style type="text/css">
    body {
    background-image: url(assets/images/Business%20Men%20In%20Reception%20Col.2.jpg);
    background-repeat: no-repeat;
    background-color: #003;
    margin-left:auto;
    margin-right:auto;
    position: relative;
    width: 960px;
    It's a good idea not to use spaces or any punctuation in your filenames when working for the web.
    #header {
    margin-left:auto;
    margin-right:auto;
    position: relative;
    width: 960px;
    #heading {
    font-family: Georgia, "Times New Roman", Times, serif;
    font-size: 36px;
    font-style: italic;
    font-variant: normal;
    margin-left:auto;
    margin-right:auto;
    There's no need to specify the default values (font-variant:normal) or to specify auto margins for any block element without an explicitly defined width. And wouldn't it make more sense to put the font style on the body tag, where it will inherit into the rest of the page than to restate it as you have done in the next rule?
    #bodytext {
    font-family: Georgia, "Times New Roman", Times, serif;
    font-size: 18px;
    line-height: 25px;
    font-variant: normal;
    width: 300px;
    #container {
    width: 960px;
    position: relative;
    margin-left:auto;
    margin-right:auto;
    .rightimg {
    float: right;
    margin-left: auto;
    padding-right: 40px;
    #heading #navbar ul li {
    padding: 30px;
    </style>
    Margin-left:auto can't work without knowing what the width of the element is....  Keep your CSS lean and targeted - it will help you to debug your layouts.

  • I want to update  timestamp(3) column with respect to varchar2

    Hi all,
    I have a date field column with varchar2 as datatype :
    create table t1 (id number,date1 varchar2(35))
    insert into (1,' 3/13/2011 10:22 AM');
    insert into (2,' 3/14/2011 10:22 AM');
    insert into (3,' 3/15/2011 10:22 AM');
    I want to update table2
    create table t1 (id number,date1 timestamp(3))
    insert into (1,' ');
    insert into (2,' ');
    insert into (3,' ');I want to update t2 with date column in t1
    can any one help me
    Thanks in advance!!!!!

    Hi,
    846773 wrote:
    Hi all,
    I have a date field column with varchar2 as datatype : That's not a very good idea. You should always use a DATE or TIMESTAMP column for dates.
    create table t1 (id number,date1 varchar2(35))
    insert into (1,' 3/13/2011 10:22 AM');Thanks for posting the CREATE TABLE and INSERT statements; that's very helpful.
    Test them and make sure they work before you post them. You forgot the table name (after the keyword INTO).
    insert into (2,' 3/14/2011 10:22 AM');
    insert into (3,' 3/15/2011 10:22 AM');
    I want to update table2
    create table t1 (id number,date1 timestamp(3))This is the same name you used for the other table. I'll assume you meant to say t2 here, not t1.
    insert into (1,' ');Don't try to insert a string (such as ' ') into a TIMESTAMP column, You can INSERT a literal NULL, or simply not INSERT anything into that column.
    insert into (2,' ');
    insert into (3,' ');I want to update t2 with date column in t1Use TO_TIMESTAMP to convert the string into a TIMESTAMP:
    MERGE INTO     t2     dst
    USING  (
               SELECT  id
            ,        TO_TIMESTAMP ( date1
                              , 'MM/DD/YYYY HH:MI AM'
                       )      AS ts
            FROM    t1
           )          src
    ON     (src.id     = dst.id)
    WHEN MATCHED THEN UPDATE
    SET     dst.date1 = src.ts
    ;

  • How to Update a particular column with custom SQL in JHeadstart

    Hi Friends,
    I was trying to keep an update SQL statement in VO (missing right Parenthesis exception is thrown)
    Please to let you know about my Requirement.
    I have a column in Sales_Person Table "TARGET' and in Sales_Admin Table "INCENTIVE"
    So Admin will allot a particular Amount in Incentive column for all the sales. (i.e globally for one and all)
    When a Sales_Person enter a target of some number say 80 in the Target field.
    while saving i want to deduct the target from incentive and the result must be update in Incentive column.
    can you please suggest me where should i keep this functionality
    Can you please help me out in solving this issue.
    Thanks in advance.
    Rahul

    Rahul,
    You can do this in the doDMl method of your Entity Object.
    See this white paper:
    http://www.oracle.com/technology/products/jdev/collateral/papers/10131/businessrulesinadfbctechnicalwp.pdf
    If you have follow-up questions, please use the JDeveloper forum, since your question is not related to JHeadstart.
    Steven Davelaar,
    JHeadstart Team.

  • Add column with row number to table

    Hi,
    to a table view I'd like to add a new column that contains the row number for each row.
    I have many data sources (twelve) and with the union operator I create one output dataset. The output data is sorted by the arrangement of the input ports of the union operator.
    Is there a way to add a column with its corresponding entry number?
    Regards, FT

    I have a similar question to the original post. It seems your answer will fill the new field in all rows with the same value. But, what if we want an actual row number?
    I am simply looking to add a row number to a table. I only have one data source. The business scenario is that the output of the data service is sorted in descending order on value. I want to be able to select the first 10 (i.e. the top 10 items based on that value).
    Even if I can solve my business scenario without using a row number field after the sort, it seems like a technique that would come in handy. 
    Any ideas? I'm pretty new to using Visual Composer so I may be missing something obvious.

  • Creating a view with a 2 same tables

    Hi experts. I have a Question... I want to make a view but I need to use the KNA1 table, but... I need again the KNA1 table to make a joing like this: KNA1_1.  and KNA1_2.KUNNR. But in the transaction se11, I don't know how can I make the alias for the KNA1 table, with the alias I could add KNA1 and do a join with KNA1 again.
    Thank you for your help!
    Lulú McDonald

    Hi Ashish... I want do the following:
    I need to do in a view 2 joins with the Customer Master table, but  I want reference 2 differents clients, to the second table KNA1 I want to use an alias... then How could do I the followin joins?:
    KNA1.COUNC=T005F.COUNC
    KNA1.LAND1= T005F.LAND1
    KNA1.REGIO=T005F.REGIO
    KNA1.KUNNR=LIKP.KUNAG
    LIKP.KUNNR=KNA1_1.KUNNR
    How you can see the KNA1_1 do not exist, but I want to use them like an alias of KNA1... them I don't know how in the se11,  when I'm making a view, how add a table with an alias name.
    Thank you!!!
    Lulú

  • Finding Updated Columns with Values in Rows

    Hello,
    I have a one requierment as below.
    if I have Table ITEM with Below records
    ParcelID 
    ItemCode
    CurrentLocation
    Destination
    UpdatingTime
    1010         
    GLS
    ABC
    XYZ
    01-12-14
    1015         
    PHM
    SSS
    ZZZ
    01-12-14
    If any of the column value is updated it will replicate to ITEMUPDATE table with old row and new row as well.
    Suppose for ParcelID 1010 CurrentLocation Changed from ABC to CDE it will store in ITEMUPDATE table with both records
    old and new and if ParcelID 1015 CurrentLocation Changed from SSS to KKK it will also store as below.
    Now ITEMUPDATE table will have all records old as well as new rows as below.
    ParcelID
    ItemCode
    CurrentLocation
    Destination
    UpdatingTime
    1010      
    GLS
    ABC
    XYZ
    01-12-14
    1010      
    GLS
    CDE
    XYZ
    02-12-14
    1015      
    PHM
    SSS
    ZZZ
    01-12-14
    1015      
    PHM
    KKK
    ZZZ
    01-12-14
    Like this any column can update not only CurrentLocation.
    Now the requirement is I want to know which columns is updated and what is the new value.
    Some what results need to look like below.
    ParcelID
    Old_CurrentLocation
    New_CurrentLocation
    1010     
    ABC
    CDE
    1015     
    SSS
    KKK
    Please Anyone Can help me on this .
    Thank You,
    Avis

    Hello Avis,
    You need to store date and time in 'UpdatingTime' column in both ITEM and ITEMUPDATE tables.
    If you store only date, you will not get desired results as there may be multiple records for a 'ParcelID' in the same date in ITEMUPDATE table. It is difficult to get the latest record from multiple records with same dates for a 'ParcelID' from ITEMUPDATE.
    Alternatively you can create a surrogate key   , like 'ItemUpdateID', in ITEMUPDATE from which we can get the latest record for a 'ParcelID'. The surrogate key can be a integer identity column so that automatically incremented and updated for each insert
    in ITEMUPDATE. Then it is easy to get latest UpdatingTime for a ParcelID from ITEMUPDATE  table.
    If the table design and data is something as below:
    ITEM table
    ParcelID    ItemCode    CurrentLocation    Destination    UpdatingTime
    1010         GLS                ABC                     XYZ              
    2014-01-12
    1011         MMX               ABD                     XVB  
                2014-01-12
    1015        PHM                SSS                     ZZZ               
    2014-01-12
    ITEMUPDATE table
    ItemUpdateID    ParcelID    ItemCode    CurrentLocation    Destination    UpdatingTime
    1                         1010         GLS                
    ABC                     XYZ          2014-01-12
    2                         1015         PHM                SSS             
            ZZZ          2014-01-12
    3                         1015         PHM               
    KKK                      ZZZ          2014-02-12
    4                         1010         GLS                
    CDE                      XYZ          2014-02-12
    5                         1011         MMX               
    ABD                      YYY           2014-01-12
    Here 'ItemUpdateID' is identity column.
    The SELECT query can be written as below:
    SELECT A.ParcelID, A.ItemCode,
    B.CurrentLocation 'New_Location',
    ISNULL((SELECT CurrentLocation FROM ItemUpdate WHERE ItemUpdateID = (SELECT MAX(D.ItemUpdateID)
    FROM ItemUpdate D WHERE D.ItemUpdateID < B.ItemUpdateID AND D.ParcelID = B.ParcelID)), A.CurrentLocation) 'Old_Location'
    FROM Item A
    LEFT JOIN ItemUpdate B On B.ParcelID = A.ParcelID
    AND B.ItemUpdateID = (SELECT MAX(ItemUpdateID) FROM ItemUpdate C WHERE C.ParcelID = B.ParcelID)
    The result will be as follows:
    ParcelID    ItemCode    New_Location    Old_Location
    1010          GLS              CDE                   ABC
    1011          MMX             ABD                    ABD
    1015          PHM             KKK                     SSS

  • Dynamic update of column with values derived by formula on other table.

    i have 3 tables; table A,B and C
    table A has two columns (id and Quantity), based on the id value, the quantity value is computed using a formula on two rows (one from table B and the other from C).
    the formula is different for each id value.
    but after every month the quantity value has to be updated (because tables B & C get updated monthly).
    example. given id=1, quantity= select round((sum(h.col1)/sum(p.col1), 2) from B p, C h
    given id=2, quantity=select round((sum(col1)/sum(col3)), 2) from C
    so for every id the quantity is derived by a different formula, but the quantity value has to be recomputed every month.
    need help.

    1. update table a
    quantity = decode (id,1, <formul1>, id,2 , formula 2...)
    2. if you wanto schedule this as monthly task
    use dbms_job.submit
    send the above query to "What" parameter.

Maybe you are looking for