Help with Trigger

Last post 05-31-2012 2:38 PM by Cholotron. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 05-25-2012 4:10 PM

    Help with Trigger

    I think a trigger will be the solution:

    if the sec_qtycomplete or the sec_qtyestimate changes, I would like to update the seq_totalqty:  (sec_qtycomplete + sec_qtyestimate )

    ratter than "UPDATE seq_lines SET seq_totalqty = (sec_qtycomplete  + sec_qtyestimate) WHERE sec_index = 12345"

    can it be done?

    Thanks!!!

    Cholotron 

     

     

     

  • 05-25-2012 6:18 PM In reply to

    Re: Help with Trigger

     Triggers can be very tricky.  If your application, and any application that accesses the data, can be guaranteed to be SQL based (ODBC, OLEDB, etc) a trigger might work.  If any application touches that data using Btrieve, then it won't be able to perform Insert or Updates (assuming your create Insert and Update triggers).  You'll get status 149. 

    That being said, I think the UPDATE is going to be the better choice.  You would need a trigger on both Inserts and Updates (to cover both cases where sec_qtycomplete or sec_qtyestimate change.  

    Also, if your database schema can be changed, I would suggest not storing a calculated field.  Storing a calculated field like this introduces the exact problem you're trying to solve.  If you don't store that calculated field but handle it in the application, you won't have to update the calculated value (sec_totalqty) when either value (sec_qtycomplete or sec_qtyestimate) change. 

  • 05-30-2012 9:02 AM In reply to

    Re: Help with Trigger

    Thanks for you comments.

    I will use the update. It is simpler

    Wink 

    Cholotron 

     

  • 05-31-2012 2:38 PM In reply to

    Re: Help with Trigger

     CALL update_seceqty(12345)


    CREATE PROCEDURE update_seceqty(in :Sec_id integer);
    BEGIN
    UPDATE seq_lines SET seq_totalqty = (sec_qtycomplete  + sec_qtyestimate) WHERE sec_index = :Sec_id;
    END;

    hehehe

    same thing right?

    Stick out tongue 

     

Page 1 of 1 (4 items)