Subject Re: [ib-support] Trigger - Column Unknown
Author Milan Babuskov
gorepj wrote:
> Hi,
> I'm trying to create a trigger but I keep getting Column Unknown
> error.
>
> SET TERM ^ ;
> CREATE TRIGGER UPDATE_BALANCE_POSTINSERT FOR CURRENTACCOUNT
> AFTER INSERT AS
> BEGIN
> if (BALANCE.SUMOFNET_CHANGE IS NULL) THEN
> INSERT INTO BALANCE (SUMOFNET_CHANGE) VALUES (new.debit -
> new.credit);
> ELSE
> UPDATE BALANCE SET SUMOFNET_CHANGE = SUMOFNET_CHANGE +
> new.debit - new.credit;
> END ^
> SET TERM ; ^
>
>
> The Error is associated with BALANCE.SUMOFNET_CHANGE where BALANCE
> is another Table in the same database.

You have created the trigger for CURRENTACCOUNT. How do you expect
database to know which record do you want from table BALANCE ?

Perhaps you should do:

select SUMOFNET_CHANGE
from BALANCE
where ??? = ??? <- connection between CURRENTACCOUNT and BALANCE
into :sumofnet_change;

IF (sumofnet_change IS NULL) THEN
...

Don't forget to declare "sumofnet_change" variable.

HTH

--
Milan Babuskov
http://fbexport.sourceforge.net