If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > More triggers

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-07-05, 10:52
dvtdbd dvtdbd is offline
Registered User
 
Join Date: Feb 2005
Location: Barcelona
Posts: 42
Question 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;

Reply With Quote
  #2 (permalink)  
Old 03-07-05, 17:21
fohana fohana is offline
Registered User
 
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
Reply With Quote
  #3 (permalink)  
Old 03-08-05, 05:15
dvtdbd dvtdbd is offline
Registered User
 
Join Date: Feb 2005
Location: Barcelona
Posts: 42


Thanks.

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

Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On