Results 1 to 3 of 3

Thread: More triggers

  1. #1
    Join Date
    Feb 2005
    Location
    Barcelona
    Posts
    42

    Question Unanswered: More triggers



    Could next 3 triggers be unified (3 triggers --> 1 trigger)? By means of conditional sentences perhaps?

    CREATE TRIGGER capuntes_upd_1
    AFTER UPDATE OF empcode, fecha, asient, cuenta, codaux, ctaaux, proyec, seccio, sistem, debe, haber, divdeb, divhab, apteid, moneda ON capuntes
    REFERENCING NEW AS nxt OLD AS prv
    FOR EACH ROW MODE DB2SQL
    WHEN (
    prv.fecha != nxt.fecha OR
    prv.asient != nxt.asient OR
    prv.cuenta != nxt.cuenta OR
    prv.codaux != nxt.codaux OR
    prv.ctaaux != nxt.ctaaux OR
    prv.moneda != nxt.moneda OR
    prv.empcode != nxt.empcode OR
    prv.proyec != nxt.proyec OR
    prv.seccio != nxt.seccio OR
    prv.sistem != nxt.sistem OR
    prv.debe != nxt.debe OR
    prv.haber != nxt.haber OR
    prv.divdeb != nxt.divdeb OR
    prv.divhab != nxt.divhab
    )
    BEGIN ATOMIC
    CALL capuntes_saldos('U', prv.fecha, prv.asient, prv.cuenta, prv.codaux, prv.ctaaux, prv.moneda, prv.empcode, prv.proyec, prv.seccio, prv.sistem, -prv.debe, -prv.haber, -prv.divdeb, -prv.divhab);
    CALL capuntes_saldos('U', prv.fecha, prv.asient, prv.cuenta, prv.codaux, prv.ctaaux, prv.moneda, prv.empcode, prv.proyec, prv.seccio, prv.sistem, prv.debe, prv.haber, prv.divdeb, prv.divhab);
    END;

    CREATE TRIGGER capuntes_upd_2
    AFTER UPDATE OF empcode, fecha, asient, cuenta, codaux, ctaaux, proyec, seccio, sistem, debe, haber, divdeb, divhab, apteid, moneda ON capuntes
    REFERENCING NEW AS nxt OLD AS prv
    FOR EACH ROW MODE DB2SQL
    WHEN (prv.cuenta != nxt.cuenta)
    BEGIN ATOMIC
    CALL capuntes_cimpcont(prv.apteid, nxt.cuenta);
    END;

    CREATE TRIGGER capuntes_upd_3
    AFTER UPDATE OF empcode, fecha, asient, cuenta, codaux, ctaaux, proyec, seccio, sistem, debe, haber, divdeb, divhab, apteid, moneda ON capuntes
    REFERENCING NEW AS nxt OLD AS prv
    FOR EACH ROW MODE DB2SQL
    WHEN (prv.cuenta != nxt.cuenta)
    BEGIN ATOMIC
    UPDATE cefectos SET cuenta = nxt.cuenta, user_updated = USER, date_updated = CURRENT TIMESTAMP WHERE apteid = prv.apteid;
    END;


  2. #2
    Join Date
    Jan 2005
    Location
    Rio de Janeiro - Brazil
    Posts
    28

    I think so

    You can use the IF statement to specify the situations in which each action should be triggered.

    Take a look at the SQL Reference, Vol 2, for more info on this statement.

    Hope this Helps.

    Fernando

  3. #3
    Join Date
    Feb 2005
    Location
    Barcelona
    Posts
    42


    Thanks.

    This is exactly the answer I was waiting for...


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •