Subject Re: [firebird-support] Help with Trigger
Author Helen Borrie
At 01:44 PM 16/07/2004 +0200, you wrote:
>Hi
>
>I would like to create a trigger(Before Insert) on table A,
>that will select a date in table B. And if the date in table A
>is bigger than the date in B, disallow the current insert into A.
>
>Can anyone please help me with the syntax.
>
>The body should be something like:
>
>begin
> select BDate from B where B.cd = new.cd;
> if (B.BDate <= new.ADate) CANCELINSERT
>end

You can't use an Insert trigger to cancel an insert!! What you can do is
raise an exception, which will pass control back to the application. The
application can listen for the exception and take whatever steps are
necessary to prevent the insertion from happening.

Example:

create exception invalid_date 'Blah';
commit;

create trigger....

declare vali_date date;
as
begin
select BDate from B where B.cd = new.cd
into :vali_date;
if (vali_date <= new.ADate) then
exception invalid_date 'Date must be later than '||cast (:vali_date as
char(11));
end

/heLen