Subject Re: [firebird-support] some SQL Question
Author Helen Borrie
At 09:36 AM 30/10/2003 +0100, you wrote:
>Hi all
>
>Im now working with firebird for a weak or two, and Now im at an intresting
>part of the database..... triggers...
>
>And I can't succeed getting this right.
>
>Table 1
>
>OPTICIAN
> ID,
> NAME,
> CATEGORY_ID
>
>Table 2
>
>SALES
> ID,
> OPTICIAN_ID,
> CATEGORY_ID
>
>I would like after insert on SALES
>
>Select category_id from OPTICIAN where ID = x
>
>Update SALES set CATEGORY_ID = (selected category_id)
>
>Thus anyone have segestions.

Setting column values won't work in an After trigger - you have to do it in
a Before trigger. New.column values are read-only once the Before triggers
have finished.

create trigger bi_sales for sales
active before insert position 0
as
declare variable newcat integer;
begin
select category_id from optician where ID = new.optician_id
into :newcat;
new.category_id = newcat;
end

heLen