Subject Re: [firebird-support] Trigger is not 100%
Author Helen Borrie
At 05:23 PM 3/11/2003 +0000, you wrote:
>My setup is this I have table A and table B. I have a afterinsert
>trigger on table B that could update a record on table A. For example
>
>table A fields
>--------------
>itemid
>itemname
>requestqty
>
>table B fields
>--------------
>itemid
>requestdate
>request
>
>my trigger on afterinsert on table B is this ...
>
>update table A
>set requestqty = requestqty + new.request
>where itemid = new.itemid
>
>I have encountered that there are times that after a record was
>inserted on the table B... the record on the table A wasn't not updated.

If requestqty in table A is null, and you add new.request to it, the result
will be null, not the value of new.request.

If you are using fb 1.5, you can handle this by using the coalesce function:

set requestqty = coalesce(requestqty, 0) + new.request

In other versions, write a stored procedure to handle the null and call it
from your trigger, or use a UDF.

heLen