Subject RE: [firebird-support] trigger problem
Author Alan McDonald
> Iam having a problem where it seems that the trigger didn't fire, but as
> Helen says trigger always fire, it just depend on how we program it. Can
> you guys please take a look at my trigger and tell me how could be the
> problem that makes it unable to work properly?
>
> In the invoicedetails table I have this after insert trigger.
>
> update items
> set left = left + (new.qty*new.conversion)
> where id = new.itemid;
>
> I always have value for the itemid, qty, and conversion field. I don't
> know where to look that cause my problem.
>
> Thanks
>
> James

but if left is NULL you will always get NULL as the answer.
You need to use the COALESCE function

UPDATE ITEMS SET LEFT=COALESCE(LEFT,0)+(NEW.QTY*NEW.CONVERSION) WHERE
ID=NEW.ITEMID;

As you say the other values are also required to be NOT NULL for this to
work.
Alan