Subject Re: [firebird-support] Re: Query a table within its trigger
Author Milan Babuskov
hanszorn2000 wrote:
> declare LOCATION integer;
> declare ARTICLEID varchar(20);
> BEGIN
> select first 1 NEWLOCATION, ARTICLEID from ARTICLE
> where ARTICLE.CUSTID = NEW.CUSTID
> and ARTICLE.ISACTIVE = 'F'
> and ARTICLE.NEWLOCATION is not null
> order by NEWLOCATION
> into :LOCATION, :ARTICLEID;
>
> NEW.NEWLOCATION = LOCATION;

You have a potential bug here. What if select does not return a row? In
that case variable LOCATION has uninitialized value, i.e. it could
contain anything (perhaps a value from some previous run). Try adding...

LOCATION = NULL;

...before the SELECT query.

HTH

--
Milan Babuskov

==================================
The easiest way to import XML, CSV
and textual files into Firebird:
http://www.guacosoft.com/xmlwizard
==================================