Subject Re: [firebird-support] Re: Update generators inside a stored procedure
Author Helen Borrie
At 10:04 AM 29/07/2008, you wrote:


>I have written a trigger that looks something like this:
>
>SET TERM ^ ;
>CREATE TRIGGER GET_ID FOR JOBS ACTIVE
>BEFORE INSERT POSITION 0
>AS
> DECLARE VARIABLE NICK VARCHAR(16);
> DECLARE VARIABLE B INTEGER;
> DECLARE VARIABLE SQL VARCHAR(1024);
>BEGIN
> /* get a generator name based on design's nickname */
> SELECT NICKNAME FROM DESIGNS
> WHERE DESIGN.ID = NEW.ID
> INTO :NICK;
> SQL = 'SELECT GEN_ID(D_' || NICK || '_ID,1) FROM rdb$database';
> EXECUTE STATEMENT SQL INTO :B;
> NEW.BATCHNO = B;
>END^
>SET TERM ; ^
>
>Until I added the clause 'FROM rdb$database', I was getting errors
>regarding an 'Unexpected end of command'. What role does this clause
>play?

Well, a SELECT statement needs a FROM clause - always!!

RDB$DATABASE happens to be a table that exists in all databases that has the essential guarantee ( for SELECT ...INTO) to be a table with exactly one record.

./heLen