Subject | Re: [firebird-support] Calling Stored Procedure from Trigger |
---|---|
Author | Nando Dessena |
Post date | 2009-08-14T08:01:25Z |
Bill,
b> I have a Trigger as follows
b> CREATE TRIGGER BI_SALES_PER_WEEK FOR SALES ACTIVE AFTER INSERT OR UPDATE POSITION 2 AS
b> declare variable AVG_PERWEEK NUMERIC(15,2);
b> BEGIN
b> select AVG_WEEKSALES from GET_WEEKLY_SALES(NEW.MACHID,NEW.SITEID)
b> into :AVG_PERWEEK;
b> UPDATE MACHSITE
b> SET SALESPERWEEK = :AVG_PERWEEK
b> WHERE MACHID = NEW.MACHID AND
b> SITEID = NEW.SITEID;
b> END
b> I want to call a Stored Procedure named GET_WEEKLY_SALES which
b> returns the AVG_WEEKSALES value. Is this the correct way to call a
b> Stored Procedure from within a Trigger? I have tested the Stored
b> Procedure in Database Workbench and it gives the correct value, yet the Trigger comes up with Null.
looks pretty much ok to me, but I would need to also see the table
and SP definitions. You are most probably not testing the SP with the
exact same input data it gets when called from the trigger.
P.S. Always remember that local variables are not automatically
initialized, and a select...into that does not return any rows will
not change the variable contents (or garbage).
Ciao
--
Nando Dessena
======================================================
I support Firebird, I am a Firebird Foundation member!
Join today at http://www.firebirdsql.org/ff/foundation
======================================================
b> I have a Trigger as follows
b> CREATE TRIGGER BI_SALES_PER_WEEK FOR SALES ACTIVE AFTER INSERT OR UPDATE POSITION 2 AS
b> declare variable AVG_PERWEEK NUMERIC(15,2);
b> BEGIN
b> select AVG_WEEKSALES from GET_WEEKLY_SALES(NEW.MACHID,NEW.SITEID)
b> into :AVG_PERWEEK;
b> UPDATE MACHSITE
b> SET SALESPERWEEK = :AVG_PERWEEK
b> WHERE MACHID = NEW.MACHID AND
b> SITEID = NEW.SITEID;
b> END
b> I want to call a Stored Procedure named GET_WEEKLY_SALES which
b> returns the AVG_WEEKSALES value. Is this the correct way to call a
b> Stored Procedure from within a Trigger? I have tested the Stored
b> Procedure in Database Workbench and it gives the correct value, yet the Trigger comes up with Null.
looks pretty much ok to me, but I would need to also see the table
and SP definitions. You are most probably not testing the SP with the
exact same input data it gets when called from the trigger.
P.S. Always remember that local variables are not automatically
initialized, and a select...into that does not return any rows will
not change the variable contents (or garbage).
Ciao
--
Nando Dessena
======================================================
I support Firebird, I am a Firebird Foundation member!
Join today at http://www.firebirdsql.org/ff/foundation
======================================================