Subject RE: [firebird-support] some SQL Question
Author Thomas Steinmaurer
Hi Richard,

> 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)

Use an BEFORE INSERT trigger if you want to set a column for the
table the trigger fires.


SET TERM ^^ ;
CREATE TRIGGER TRI_SALES_UPDATECATEGORY_ID FOR SALES
ACTIVE BEFORE INSERT POSITION 0 AS
DECLARE VARIABLE ACATEGORY_ID INTEGER;
begin
SELECT CATEGORY_ID FROM OPTICIAN WHERE ID = NEW.OPTICIAN_ID INTO :ACATEGORY_ID;
NEW.CATEGORY_ID = ACATEGORY_ID;
end
^^
SET TERM ; ^^



HTH,
Thomas Steinmaurer

The IB LogManager Product Family
Logging/Auditing Suite for InterBase and Firebird
http://www.iblogmanager.com