Updating parent record owner to top 1 child record owner?

I am trying to understand how to update a parent record's owner field to the value of a child record's owner field, but while there is only ever one parent record, there are multiple children, and I want to update the parent owner value to the owner
of the first child record ever created for said parent.
So for example, if the first child record created was owned by Joe Smith and the second child record created was owned by Betty Boop, I want to update the parent record to being owned by Joe Smith since he was the owner of the original child record.
Key fields are Parent.ID, Child.ID, Parent.Owner, Child.Owner, Child.DateCreated. Hope that makes sense! It seems like using top 1 would be needed but I'm not entirely sure how to use it correctly with an update statement. I am generally pulling data not
updating it, so I'm a bit out of my element.
Thanks,
Shaunna

UPDATE t2
SET Owner = t1.Owner
FROM Parent t2
INNER JOIN Child t1
ON t2.ID = t1.ParentID
WHERE NOT EXISTS
SELECT 1
FROM Child
WHERE ParentID = t1.ParentID
AND DateCreated < t1.DateCreated
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My Wiki User Page
My MSDN Page
My Personal Blog
My Facebook Page

Similar Messages

  • How to update child record when item from parent record changes

    Hi, I have a master and detail form with two regions on the same page.
    Region one references parent record, one of column in the parent record is also in the child record. And is one to many relation
    between parent record and child record. How can I have the column on the child record updated when the column of the parent record is being modified?
    For exemple; Parent record has two columns : ID and Program.
    Child record has Program, goal# and status. I have two pages established, page 27 and page 28.
    Page 27 list out all programs from parent record, by clicking on edit to a program, it braches to page 28 with program listed as editable field in region one, and mulitple records list in region two from the child record with the same program.
    The problem that I am having is once the program in region one got modified using ApplyMRU, the program in child record did not get updated with the new value and therefore those record become orphan records. I need a way to update all current child records with the new program value.
    Thanks in advance for anyone who can hlep out on this problem.
    Julie
    Edited by: JulieHP on May 24, 2012 4:57 PM

    One Idea is
    If possible create a after update database trigger on the parent table to update the relevant child record.
    Next one
    Create a PL/SQL process on the parent page with process sequence next to ApplyMRU, so when the ApplyMRU is seccessfull it goes not to your process where you can have your update statement

  • UPDATING child table based on the mods to parent record

    I have a one to many relationship between Table A and Table B.
    I have a field in both of my tables that tracks the status of the record in each table. ie: submitted, inprogress, done.
    When records are created in Table A and B, status is set to SUBMITTED. When the application is being reviewed, the status in parent table is changed to INPROGRESS. As soon as the status in Table A changes to INPROGRESS for the parent record, i also want the status in Table B to change to INPROGRESS for the corresponding child records.
    How can I do this? Triggers is one of the solns, but is there something that i can do with the PROCESS option available on the parent form?
    Any help is very much appreciated.

    Hi,
    Firstly, as Oracle is a relational database, you shouldn't need to have the setting on a child record where it will always be the same as the parent record.
    Secondly, a trigger is probably a better place to make the update, if you need to do this, as this would also handle updates outside of Apex.
    Finally, yes you can create a process to do this if you want. You can create an unconditional process (that is, it runs whenever the page is submitted) and does something like:
    UPDATE TABLEB
    SET STATUS = :P1_STATUS
    WHERE FK_ID = :P1_PK_ID
    AND STATUS &lt;&gt; :P1_STATUSAndy

  • How to update parent and child tables while updating parent table

    I have a parent table EMPLOYEE which includes columns (sysid, serviceno,employeename...) sysid is Primary key, serviceno is Unique key and I have child table DEPENDENT includes columns (sysid,employee_sysid,name,dob...) here again SYSID is primary key for DEPENDENTS table, employee_sysid is Foreign key of EMPLOYEE table.
    Now I want to change SYSID (using sequence) in EMPLOYEE table which need to be update in DEPENDENTS table as well
    Note: I have 10000 records in EMPLOYEE table as well as I have 5 more child tables which need to update new SYSID.
    please help me

    first disable the FOREIGN KEY Constraints.
    you can update Parent as well as Child record also with help of trigger.
    here i am giving you one examlpe..it may help u.
    create table parent(id number primary key,name varchar2(100))
    create table child_1(id number primary key,p_id number,dob date,
    CONSTRAINT FK_id FOREIGN KEY (p_id) REFERENCES parent (ID))
    create table child_2(id number primary key,p_id2 number,addr varchar2(1000),
    CONSTRAINT FK_id2 FOREIGN KEY (p_id2) REFERENCES parent (ID))
    insert some test data to parent and child tables.
    alter table child_2 disable constraint FK_id2
    alter table child_1 disable constraint FK_id2
    CREATE OR REPLACE TRIGGER delete_child
    BEFORE UPDATE ON parent
    FOR EACH ROW
    BEGIN
    UPDATE CHILD_1
    SET P_ID=:NEW.ID
    WHERE P_ID=:OLD.ID;
    UPDATE CHILD_2
    SET P_ID2 =:NEW.ID
    WHERE P_ID2=:OLD.ID;
    END;
    then Upadte parent table primary key col and check the child tables.
    then enable the constraints...

  • To find all the child records are processed before parent records

    Hi,
    When i am trying to process consignment pulls and my client is using third party tool to insert the data into interface tables. My logic is written in such a way that it should pick parent record associated with child but there is some delay in child records and not all the child records are being pulled with parent.
    In a brief, i need to write a condition in such a way that my parent cursor should pick all the child records with max(last_updated_date) and then it should be processed.
    eg: I have a family and need to catch bus with all my family members. I need to check now for the last family member who get into and should wait for atleast 2mins so as to ensure all my family members are in. I am unable to achieve this with count. Please do revert back soon.
    Details are below:
    CURSOR c_pull (p_pull_id NUMBER) IS----------------------------------parent cursor
    SELECT ecp.ROWID ROW_ID
    ,ecp.*
    FROM consignment_pulls ecp
    WHERE ecp.process_flag IN ( 2, 3 )
    AND ecp.pull_id > NVL(p_pull_id,0)
    ORDER BY ecp.pull_id
    FOR UPDATE OF ECP.PROCESS_FLAG NOWAIT;
    CURSOR c_line (p_pull_id NUMBER) IS----------------------------------child cursor
    SELECT ecpi.ROWID ROW_ID
    ,ecpi.*
    FROM consignment_pull_items ecpi
    WHERE ecpi.process_flag IN ( 2, 3 )
    AND ecpi.pull_id = p_pull_id
    FOR UPDATE OF ecpi.process_flag;
    Edited by: Prathyusha on Apr 5, 2012 12:07 AM
    Edited by: jerry on Apr 5, 2012 12:10 AM

    Hi Helios,
    Thanks for the info. But its not a concurrent request something like we can filter with start date and completion date. Its all about selection of records from headers and lines table and not able to make those selection of header records with a delay of say some 2minutes until all the child records are inserted.
    Thanks,
    Prathyusha.

  • Sum child list items and update parent total using javascript

    I have a SharePoint 2010 Parent/Child list setup using a lookup field to join both the lists, this is working well.
    The Parent list contains requisition requests and the child list contains related item details. Each of the related child list items has a 'Line Item Total' field. I need to aggregate the Line Item Totals in the child list and place the result in a 'Requisition
    Total' in the parent. So for any given parent record the sum of it's related child 'Line Item Totals' is reflected in the 'Requisition' total in the parent row.
    I am struggling with the JavaScript code below. I am trying to aggregate Line Item Totals for a given Requisition#? Could someone please review and advise?
    <script language="javascript" src="/Purchasing/Documents/jquery-1.8.2.js" type="text/javascript"></script>
    <script language="javascript" src="/Purchasing/Documents/jquery.SPServices-2014.01.min.js" type="text/javascript"></script>
    <script>
    $(document).ready(function()
     $('select[title=Requisition#]').children().attr('disabled',true);
     $("input[title='Old Amount']").attr("readonly","true").css('background-color','#F6F6F6');
       // Retrieve the name of the selected parent item.
       var strParent=$("select[title$='Requisition#'] :selected").text(); 
     splist li = web.lists["ReqDetails"]; // This is the child list
        spquery q = new spquery();
        q.Query= "<Where>" +
         "<And>" +
          "<Neq>" +
           "<FieldRef Name='ID'/><Value Type='Number'>0</Value>" +
          "</Neq>" +
          "<eq>" +
           "<FieldRef Name='LinkID'/><Value Type='Number'>ReqID</Value>" +
          "</eq>" +
         "<And>" +
        "</Where>" +
        "<OrderBy>" +
         "<FieldRef Name='LineItemTotal'/>" +
        "</OrderBy>"
        q.ViewFields = string.Concat("<FieldRef Name='LineItemTotal' />");
        q.ViewFieldsOnly = true; // Fetch only the data that we need
        splistitemcollection items = li.getitems(q);
        foreach(SPListItem item in items)
        sum += parseInt(item["LineItemTotal"], 10);
      alert(sum)
     </script>
    Rick Rofe

    I do something similar for a PO Header/PO Detail set of lists. I use SPServices to pull the data.
    I put this code in the child edit page - so any time any child is edited, the parent is updated. I get all children records and total them up (except for the item I'm displaying at the current time. I add that value in directly from the form itself.
    <script type="text/javascript" src="/Javascript/JQuery/JQueryMin-1.11.1.js"></script>
    <script src="/Javascript/JQuery/jquery.SPServices-2014.01.min.js"></script>
    <script>var poNumber = '';
    var poDetailID = '';
    $(document).ready(function() { var queryStringVals = $().SPServices.SPGetQueryString();
    poNumber = queryStringVals["PO"];
    poDetailID = queryStringVals["ID"];
    function PreSaveAction() {
    // update the PO header with the total of all items + shipping + adjustments
    var query = "<Query><Where><And><Eq><FieldRef Name='Title' /><Value Type='Text'>" + poNumber + "</Value></Eq><Neq><FieldRef Name='ID' /><Value Type='Counter'>" + poDetailID + "</Value></Neq></And></Where></Query>";
    var viewFields = '<ViewFields><FieldRef Name="Total" />';
    viewFields += '</ViewFields>';
    var poTotal = 0.00;
    $().SPServices({
    operation: "GetListItems",
    async: false,
    listName: "PO Details",
    webURL: "/po",
    CAMLViewFields: viewFields,
    CAMLQuery: query,
    completefunc: function (xData, Status) {
    //alert(xData.responseText);
    $(xData.responseXML).SPFilterNode('z:row').each(function() {
    if($(this).attr("ows_Total")) {
    //alert($(this).attr("ows_Total"));
    poTotal += Number(parseFloat($(this).attr("ows_Total").split(";#")[1],2).toFixed(2));
    // add in this changed line (we skipped it above)
    var qty = $('input[title="Quantity Ordered"]').val();
    var price = $('input[title="Price"]').val().replace(',','');
    var extend = Number(qty)*Number(price);
    poTotal += extend;
    //alert(poTotal);
    // update the PO Header
    $().SPServices({
    operation: "UpdateListItems",
    async: false,
    listName: "Purchase Orders",
    webURL: "/po",
    ID: poID,
    valuepairs: [["Total", poTotal]],
    completefunc: function (xData, Status) {
    //alert(xData.responseText);
    $(xData.responseXML).SPFilterNode('z:row').each(function() {
    return true;
    Robin

  • Deletion of child records linked to parent records to be deleted etc..

    'Combined with WHEN OTHERS, SQLCODE provides a way for you to handle different, specific exceptions without having to use EXCEPTION_INIT pragma. In the next example, I trap two parent child exceptions, -2292 and -2291, and, then take an action appropriate to each situation:
    PROCEDURE delete_company (company_id_in IN NUMBER)
    IS
    BEGIN
    DELETE FROM company where company_id = company_id_in;
    EXCEPTION
    WHEN OTHERS THEN
    DECLARE
    error_code NUMBER := SQLCODE;
    error_msg VARCHAR2(512) := SQLERM;
    BEGIN
    IF error_code = -2292 THEN
    /*Child records found. Delete these too */
    DELETE FROM employee WHERE company_id = company_id_in;
    /* Now delete parent again */
    DELETE FROM company WHERE company_id = company_id_in;
    ELSIF error_code = -2291 THEN
    /* Parent key not found */
    DBMS_OUTPUT_PUT_LINE('Invalid company id' || TO_CHAR(company_id_in));
    ELSE
    /* This is like a WHEN OTHERS inside a WHEN OTHERS */
    DBMS_OUTPUT_PUT_LINE('Error deleting company, error: ' || error_msg
    END IF;
    END;
    END delete_company;
    Sourced from Oracle PL/SQL Programming (3rd edition) P.143
    1. Are error_code and error_msg assigned automatically or do I have to include assignments? If yes, how?
    2. Where do I get a list of commonly caught Oracle error codes and similar code snippets used for business logic?
    3. How would you deal with the situation where you detect a parent while you are deleting a child record? Just warn the user and log it hoping the DBA will review the logs?
    4. I work within a project where I could not query any parent-child relationships, using, amongst other queries the following query, and, this means that the programming team might not be creating these relationships within the database (Oracle 11g).
    What are the technical risks?
    Could I be omitting something, because it seems quite incredible to me that parent-child relationships are not in place?
    SELECT a.table_name,
    a.column_name,
    a.constraint_name,
    c.owner
    FROM ALL_CONS_COLUMNS A, ALL_CONSTRAINTS C
    where A.CONSTRAINT_NAME = C.CONSTRAINT_NAME
    and a.table_name=:TableName
    and C.CONSTRAINT_TYPE = 'R'
    Sourced from http://stackoverflow.com/questions/1729996/list-of-foreign-keys-and-the-tables-they-reference

    This is bad code, very very bad code. Throw it away and start with a clear idea of what you want to do.
    Why is this code very very bad? Because it uses WHEN OTHERS not followed by a RAISE.
    Why is this code bad code? Because it uses one WHEN clause instead of several.
    Here is an example for handling multiple exceptions:
    http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/errors.htm#BABFBHGA
    If your error code does not have a predefined name, define the name yourself:
    http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/errors.htm#BABIIEFC
    If you keep the WHEN OTHERS at the end, be sure to add RAISE so the exception still exists. If you don't, Oracle will not do the automatic rollback it should be doing.
    To answer your question about parent-child relationships, it is very important to have them. They stop you deleting a parent that has children, but they do not stop you from deleting children.

  • Delete the parent records and child table records at a time

    hi all;
    I am facing the pbm like to delete the all records in child table and corresponding records in parent table at a time. so I want to delete the all the records in child table and corresponding parent records in parent table by using single SQL query. plz help me
    Thanks in advance

    You want to use one single SQL statement to delete the child records in a table and the corresponding master records in the master table??
    That's not quite possible with a single SQL, of course unless you are talking about Oracle Forms, where you have a relation and set the delete behavior to Cascading, like said in the above posts.
    Tony

  • How to obtain parent record from child record in relationship using API

    Hi,
    I have a record in the main table that is the child in a parent/child relationship to another main table record.  Using the Java API, how would I obtain the parent record in the relationship where I am starting with the child record?  In the API there seems to just be calls for getChildren, but not a getParent type call.
    Appreciate any immediate help that can be provided.
    Thanks,
    Eddie

    Hi Eddie,
    Please follow the below steps to retrieve only parents of a child Record.
    1. Create RetrieveRelationshipsCommand.
    2. Set the parameter RelationshipId.
    3. Set the parameter Anchor Record and Anchor Record Id. In this case the child record for which parents records to be retrieved.
    4. Set the parameter setGetChildren as false . This retrieves only the parent records for the specified child reocrd.
    5. Execute the RetrieveRelationshipsCommand.
    6. Retrieve member records from above step.
    Hope it helps
    Regards,
    Neeharika

  • ADF,how to delete parent record and related child record without manual cod

    Hi All,
    I'm using 11g adf.
    I have one parent table PAR and two child table CHD1 , CHD2 respectively.
    I'm inserting values in three tables , making a form having add , delete and edit buttons.
    Issue when i want to delete a record from PAR table , it gives child table record exists . i have did manual coding to delete the child records with related to the selected parent table PAR.
    Is there any process in ADF to delete the child records with respective selected parent record with out manual coding.
    thanks in advance.

    http://download.oracle.com/docs/cd/E14571_01/web.1111/b31974/bcentities.htm#BABHFJFJ
    John

  • How to find child records is exists before to delete parent records.

    Dear Everyone,
    I would like to ask you, is there any simple way to find child records is exists before to delete parent records.
    I have a master table defined primary key and I have referenced that as foreign key in many tables.
    I have used Delete_Record to delete but it isn't display the message 'child record exist' but it cleared the record from the form. So I need to know how to find child records is exists or not before to do delete_record so that I can display message in-case it exists.
    I do know we can able to check in every table matching the column manually, but what if we use 100 of tables then it is not possible to check manually.
    I am sure there must be simple way to find as how the oracle identifies when we execute delete query.
    Please help me on this.
    Thanks in advance.

    Simple solution is to run the query I have given for all child tables or to try a single query for all child tables withj something like:
    select <parent_key>
    from <parent_table>
    where <parent_key> in
              (select <foreign_key_1> from <child_table_1> union
               select <foreign_key_2> from <child_table_2> union
               ... );More complicate solution could be to change the foreign key constraints to cascade DELETE on parent table to child tables:
    SQL>
    SQL> create table p(x int primary key);
    Table created.
    SQL> create table c1(x1 int);
    Table created.
    SQL> create table c2(x2 int);
    Table created.
    SQL>
    SQL> alter table c1 add constraint fk1 foreign key(x1) references p;
    Table altered.
    SQL> alter table c2 add constraint fk2 foreign key (x2) references p;
    Table altered.
    SQL>
    SQL>
    SQL> insert into p values(1);
    1 row created.
    SQL> insert into c1 values(1);
    1 row created.
    SQL> insert into c2 values(1);
    1 row created.
    SQL> commit;
    Commit complete.
    SQL>
    SQL> alter table c1 drop constraint fk1;
    Table altered.
    SQL> alter table c2 drop constraint fk2;
    Table altered.
    SQL>
    SQL> alter table c1 add constraint fk1 foreign key(x1) references p on delete cascade;
    Table altered.
    SQL> alter table c2 add constraint fk2 foreign key (x2) references p on delete cascade;
    Table altered.
    SQL>
    SQL> delete p where x=1;
    1 row deleted.
    SQL> commit;
    Commit complete.
    SQL> select * from p;
    no rows selected
    SQL> select * from c1;
    no rows selected
    SQL> select * from c2;
    no rows selected
    SQL>Edited by: P. Forstmann on 27 oct. 2011 14:01

  • Updating multiple records from single form (ASP)

    I have a nested repeat region.
    I have created in the parent, a form with 3 fields and an update button.
    the child records all have multiple columns, 3 of which correspond to the parent.
    Athe parent is bound to the child records by the shipmentID
    I need to be able to update all child records from the form in the parent.
    The case is this.
    The child records are orders with shipdates and frequencies
    The parent contains a form with fields for shipdate and frequency
    The administrator needs to change the shipdate and/or frequency for all child records.
    (The child records are forms as well--but that's another issue that works fine)
    Shipment ID
    Date Field
    Freq Field
    UPDATE Button
    ShipmentID
    Record 1
    Data case1
    Date
    ShipmentID
    Record 2
    Data case 2
    Date
    I am doing this in classic asp with an SQL database.
    So how do I get the form to update all record
    [Subject title edited by moderator to make clear ASP involved]

    Hi,
    This is one of those questions that would require far more explanation that is reasonable to expect in a forum. You should do a little poking around in the nearest Barnes & Nobles. About a half hour in a chare with a good ASP book and vanilla latte should have you on the right track.
    Lawrence   *Adobe Community Expert*
    www.Cartweaver.com
    Complete Shopping Cart Application for
    Dreamweaver, available in ASP, PHP and CF

  • Cursor to Update Multiple Records

    Hi all
    Oracle forms V6
    I am trying to use a cursor to update multiple rows associated with the change of a single value, the tables are related but not directly through the values I am trying to change. The form is multi-tab with a block per tab. On the first tab a value entered into a specific field is subsequerntly used in another multi-record tab when the time comes to fill this in, the value is automatically inserted, and this works fine.
    If there is multiple records in the second tab then the value from the parent record will be displayed in all records in the 2nd tab because it is automatically taken from the parent record.
    I am trying to use a for-loop cursor to update more than one row when the parent value is updated, at present it only updates one row, yet a message I put in cursor shows the different values being stepped through in the cursor. I don't have much experience in this area yet but it looks like the actual form cursor needs to be moved to the next record to update that as well, as you change to this tab you can see the first record being updated but not the second.
    Cursor is in the when validate item on the first tab/block.
    DECLARE     
    v_cvs_val VARCHAR2(100) := :b1.new_value;
    CURSOR c_cvs IS
         SELECT b2.pk, b2.oldValue
         FROM T1
         WHERE T1.pk = :b2.pk;
         --result set of cursor is all records relating to current parent record
         mcec_rec c_cvs%ROWTYPE; --declares record of cursor type
    BEGIN
         IF :system.record_status = 'CHANGED' AND :b2.pk IS NOT NULL THEN
         OPEN c_cvs;
         LOOP
         FETCH c_cvs INTO mcec_rec;
         :b2.oldValue := v_cvs_val;
         EXIT WHEN c_cvs%NOTFOUND;
         END LOOP;
         CLOSE c_cvs;
         END IF;
    END;
    Any suggestions as to where i'm going wrong would be very much appreciated.
    user605593

    Do I understand correctly? It looks like you have a parent-child relationship where one of the fields on the child table has to be updated when the parent record is changed, but ONLY if the record exists in the child datablock. You don't want to update the child records which exist on the database but not in the block.
    go_block(child);
    first_record;
    loop
      :child.item := :parent.item;
      exit when :system.last_record = 'TRUE';
      next_record;
    end loop;
    go_block(parent);The code has a go_block so cannot be called from a when-validate-item trigger. You could start a timer in that trigger and run the code when the timer expires. However, the when-validate-record trigger might be better as you will not be able to navigate to the child block if there is an invalid field in the parent (eg if a not-null field is blank).

  • Update parent status based on all children status and sum of children amount.

    Hi,
    I need to write sql query for the following scenarios.
    We have 3 financial systems (sys1, sys2, sys3) where a same transaction gets entered independently into each system OR entered into one and exported to the other system. Transaction need not be in all 3 systems.
    We need to create reconcile report to see the status of transaction and display if it is reconciled or not. For this, in our stored procedure we are pulling data from 3 systems into temp tables and using CTE and other logic marking each transaction status
    in each system temp table. One of the systems (eg sys1), we made it as source.
    Sys1 temp table has both parent and child records and are distinguished using type. Sys2 and sys3 has only children records.  When report is created, we are showing parent  from sys1 temp table and
    children from new temp table where children status is updated based on availability of it in all 3 systems.
    DECLARE
    @sys1 TABLE
    ID int,
    childID varchar(20),
    ParentID varchar(20),
    RecType decimal(3,0),
    SettleDate smalldatetime,
    Principal money,
    Sys3ID varchar(16)
    NULL,
    Sys2ID int
    NULL,
                            Status varchar(25) NULL
    DECLARE
    @sys2 TABLE
    TxID int
    PRIMARY KEY NOT
    NULL,
    CommonTransactionID varchar(16),
    SettleDate smalldatetime,
    Par money,
    Sys3ID varchar(16) NULL,
    Sys1ChildID,
    Sys1ParentID bigint
    DECLARE
    @sys3 TABLE
    Sys3ID varchar(16),
    REFERENCE
    varchar(16),
    VALUE_DATE datetime,
    DIRECTION char(1),
    AMOUNT money,
    RecSource varchar(2)
    Insert Into @sys1 (ID, childID, ParentID, RecType, SettleDate, Principal)
    Select 172876, 217955, 217954, 100, ‘2015-03-01’, 100.00
    Union
    Select 172877, 217956, 217955, 50, ‘2015-03-01’, 15.00
    Union
    Select 172878, 217957, 217955, 50, ‘2015-03-01’, 25.00
    union
    Select 172879, 217958, 217955, 50, ‘2015-03-01’, 10.00
    Union
    Select 172880, 217959, 217955, 50, ‘2015-03-01’, 10.00
    union
    Select 172881, 217960, 217955, 50, ‘2015-03-01’, 40.00
    Insert Into @sys2(TxID, Sys1ID, settleDate, Par)
    Select 4336620, 217956, ‘2015-03-01’, 15.00
    Union
    Select 4336621, 217957, ‘2015-03-01’, 25.00
    union
    Select 4336613, 217958, ‘2015-03-01’, 10.00
    Union
    Select 4336614, 217959, ‘2015-03-01’, 10.00
    union
    Select 4336615, 217960, ‘2015-03-01’, 40.00
    Insert into @sys3(Sys3ID, Reference, Value_Date, Direction, Amount)
    Select 1, ‘5654471 4336620’, ‘2015-03-01’, ‘O’, 15.00
    Union
    Select 2, ‘5654481 4336621’, ‘2015-03-01’, 'O',25.00
    Union
    Select 3, ‘5654491 4336613’, ‘2015-03-01’, 'O',10.00
    Union
    Select 4, ‘5654501 4336614’, ‘2015-03-01’, 'O',10.00
    Union
    Select 5, ‘5654511 4336615’, ‘2015-03-01’, 'O', 40.00
    After going thru lot of other logic, final temp table will have only children with status assigned. The above temp table data is only for 1 scenario.
    The following are status of children.
    This is how status of children is determined:
    Not Settled – All child records start as Not settled in temp tables.
    Settled – when record exists in sys3 and other criteria is met.
    Partially settled – record exists in sys3 and either in sys1 or sys2 or other criteria is not met.
    Reconciled – child record should exist in all 3 systems and all criteria is match
    Mismatched – record has wrong amount when compared in any of 2 systems.
    **************** My Part below*******************
    My part is to update the status of parent based on children status and parent amount must match sum of child amounts. If amounts don’t match, then leave the status of parent as null.
    Determining the status of parent:
    Not Settled – None of children has yet settled.
    Settled – All children are settled.
    Partially settled – some of children are as settled OR 1+ children are partially settled.
    Reconciled – All children are reconciled.
    Partially Reconciled – some children are partially reconciled.
    Null – 1 or more childen has a status of mismatched.
    AND sum of children amount should match parent amount
    How can I update the status of parent based on all children and sum of amount of children equal to parent amount.
    Thanks,
    Spunny

    >> We have 3 financial systems (sys1, sys2, sys3) where the same transaction gets entered independently into each system OR entered into one and exported to the other system. Transaction need not be in all 3 systems. <<
    Your design is fundamentally wrong. In RDBMS, we want to have one fact, one way, in one place in the schema. The goal of all databases is to remove redundancy, not increase it. This not just SQL; this was true for hierarchical and network databases before them! 
    >> We need to create reconcile report to see the status of transaction and display if it is reconciled or not. For this, in our stored procedure we are pulling data from 3 systems into temp tables and using CTE and other logic marking each transaction
    status in each system temp table. One of the systems (eg sys1), we made it as source. <<
    You have re-invent the worst of 1970's file processing, but you want to use a temp table instead of scratch tape. This is not RDBMS or good SQL. 
    >> Sys1 temp table has both parent [sic] and child [sic] records [sic] and are distinguished using type. Sys2 and sys3 has only children [sic] records [sic]. When report is created, we are showing parent from sys1 temp table and children from new temp
    table where children [sic] status is updated based on availability of it in all 3 systems. <, 
    The terms “child” and “parent” are not part of RDBMS. They come from network databases. You are building fake pointer chains we do have referenced and referencing tables. Or do you mean to model weak and strong entities? Where is the DRI actions?
    These things are not tables! They have no keys, so they are called (garbage) piles. But even the garbage is wrong. There is no generic “id” in RDBMS; it has to be “<something in particular>_id” to be valid. Since you do not do math on it, it should not
    be a numeric. 
    A “rec_type” is a nominal scale, so it cannot be a numeric either! Likewise, we have no generic “status”, but a status is state of being so it has to have a temporal dimension. And did you know that “reference” is a reserved word in SQL as well as another ISO-11179
    violation. 
    The MONEY data type does not do correct math. Google it! It is another Sybase left-over that nobody should ever use. 
    Finally, you used the old Sybase INSERT INTO ..SELECT..), .. disaster instead of the ANSI/ISO Standard VALUES table constructor. 
    >> This is how status of children [sic] is determined: ..
    My part is to update the status of parent [sic] based on children [sic] status and parent [sic] amount must match sum of child [sic] amounts.<<
    Your narrative describes what Tom Johnston called a Non-Normal Form Redundancy. We do not put summary data in the strong entity; another basic data modeling principle. We build a VIEW that gives us the current summary. Your mindset is still in punch cards and
    magnetic tape files. 
    "No matter how far you have gone down the wrong road, turn around!" -- Turkish proverb. 
    Can you start over and do it right? 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Can't Delete Parent Record - On Delete Cascade is set

    Greetings all,
    I have a parent and child table and when I attempt to delete the parent record, I get the following error:
    ORA-02292: integrity constraint (WFSTEADMAN.INCIDENT_NOTES_TBL_FK) violated - child record found
         Error      Unable to process row of table MYTEST_INCIDENTS.
    I have the the FK set to ON DELETE CASCADE so I am not sure what the issue might be.
    Below are the structures of my parent and child tables:
    I am using apex.oracle.com so the version is: Application Express 4.0.2.00.06
    Any assistance would be appreciated.
    Wally
    PARENT TABLE:
    =============================================================
    CREATE TABLE "MYTEST_INCIDENTS"
    (     "INCIDENTID" NUMBER NOT NULL ENABLE,
         "INCIDENTCREATED" DATE NOT NULL ENABLE,
         "INCIDENT_OWNER" VARCHAR2(200) NOT NULL ENABLE,
         "DTGSTART" DATE NOT NULL ENABLE,
         "DTGEND" DATE,
         "INCIDENT_SERVICES" VARCHAR2(4000),
         "INCIDENT_CUSTOMERS" VARCHAR2(4000),
         "INCIDENT_DESCRIPTION" VARCHAR2(4000),
         "INCIDENT_TIMELINE" VARCHAR2(4000),
         "INCIDENT_TRACKING" VARCHAR2(500),
         "INCIDENT_RESTORE" VARCHAR2(4000),
         "INCIDENT_FOLLOWUP" VARCHAR2(4000),
         "INCIDENT_LEVEL" NUMBER,
         "INCIDENT_TITLE" VARCHAR2(500),
         "EMAIL_NOTIFY" VARCHAR2(4000),
         "TEXT_NOTIFY" VARCHAR2(4000),
         "LEVEL_TYPE" VARCHAR2(25),
         CONSTRAINT "MYTEST_INCIDENTS_PK" PRIMARY KEY ("INCIDENTID") ENABLE
    CREATE OR REPLACE TRIGGER "BI_MYTEST_INCIDENTS"
    before insert on "MYTEST_INCIDENTS"
    for each row
    begin
    if :NEW."INCIDENTID" is null then
    select "MYTEST_INCIDENTS_SEQ".nextval into :NEW."INCIDENTID" from dual;
    end if;
    end;
    ALTER TRIGGER "BI_MYTEST_INCIDENTS" ENABLE;
    CHILD TABLE
    =============================================================
    CREATE TABLE "MYTEST_INC_NOTES"
    (     "NOTEID" NUMBER NOT NULL ENABLE,
         "INCIDENT_ID" NUMBER NOT NULL ENABLE,
         "NOTE_DTG" DATE,
         "NOTE_OWNER" VARCHAR2(200),
         "NOTE_COMMENTS" VARCHAR2(4000),
         CONSTRAINT "MYTEST_INC_NOTES_PK" PRIMARY KEY ("NOTEID") ENABLE
    ) ;ALTER TABLE "MYTEST_INC_NOTES" ADD CONSTRAINT "MYTEST_INC_NOTES_CON" FOREIGN KEY ("INCIDENT_ID")
         REFERENCES "MYTEST_INCIDENTS" ("INCIDENTID") ON DELETE CASCADE ENABLE;
    CREATE OR REPLACE TRIGGER "BI_MYTEST_INC_NOTES"
    before insert on "MYTEST_INC_NOTES"
    for each row
    begin
    if :NEW."NOTEID" is null then
    select "MYTEST_INC_NOTES_SEQ".nextval into :NEW."NOTEID" from dual;
    end if;
    end;
    ALTER TRIGGER "BI_MYTEST_INC_NOTES" ENABLE;
    CREATE OR REPLACE TRIGGER "MYTEST_INC_NOTES_T1"
    BEFORE
    insert or update on "MYTEST_INC_NOTES" REFERENCING NEW AS NEW OLD AS OLD
    for each row
    begin
    :NEW.NOTE_DTG := SYSDATE;
    end;
    ALTER TRIGGER "MYTEST_INC_NOTES_T1" ENABLE;

    Yeah there was a rampant child table still left out there. Noticed the issue and deleted the child and all is well now. :). Should have looked for a couple more minutes before posting.
    Thanks
    Wally

Maybe you are looking for

  • Load XML file from different location?

    Hi All, I've been going through an exercise by Karl Matthews to load XML data into an AIR App: http://www.adobe.com/devnet/air/flex/articles/xml_viewer_on_air.html but I would like to change where the XML file used in the project is retrieved from. C

  • Cannot combine files in Reader 9 Standard

    I'm using the standard Adobe Reader 9, just upgraded. Even in Adobe 8, there was no option for combining or merging files. These were files that I scanned in which I thought the computer had basically scanned them in as PDF files because they automat

  • Package Linked Smart Objects not available

    Hello, I have Photoshop CC on my pc and Windows 8. File > Package is not available... Can anybody help me!

  • Illustrator CS3 grays out and locks when using Save or Save As

    In the past few days everytime I try to save an existing or new file with Save or Save As i see the save dialog box flash and then the whole program locks and grays out. The only way to close is to do a control-alt-delete. This happens for new files

  • My mouse wheel won't scroll through tabs

    I can't remember if it was right when I updated to v.22, but if not then it was shortly after that my mouse wheel stopped working for scrolling through tabs. I can still scroll through pages just fine, but even on safe mode and with hardware accelera