Subject RE: [ib-support] Question about update - trigger
Author Thomas Steinmaurer
Wasith,

> What is the trigger code that will update PVI_ID in table TBADDRESS if
> PVI_ID in table CITY changed.
>
> I was try using this code but it doesn't seem to work. Thanks for your
> help
>
> CREATE TRIGGER T_TBCITY_UPVI_ID FOR TBCITY
> ACTIVE AFTER UPDATE POSITION 0
> AS
> begin
> IF (NEW.PVI_ID <> OLD.PVI_ID) THEN
> UPDATE TBADDRESS SET TBADDRESS.PVI_ID=NEW.PVI_ID where
> TBADDRESS.CIT_ID = NEW.CIT_ID;
> End

The main problem is that (NEW.PVI_ID <> OLD.PVI_ID) will fail
if either the new or the old value of PVI_ID is NULL. So, in
that case the update will simply not happen.

There is only way to "catch" a change in a column, namely with

IF (((OLD.PVI_ID IS NULL) AND (NEW.PVI_ID IS NOT NULL)) OR
((OLD.PVI_ID IS NOT NULL) AND (NEW.PVI_ID IS NULL)) OR
(OLD.PVI_ID <> NEW.PVI_ID)) THEN
UPDATE TBADDRESS ...


HTH,
Thomas Steinmaurer
http://www.iblogmanager.com