Subject Re: Timestamp - trigger
Author Adam
> I get an "Unknow token – end" here. I am using ISQL(IBExpert) to
create this
> trigger. I want to insert a timestamp when a record is inserted into
SMSQ
> table.

First things first, IIRC IBExpert has an emulator for iSQL so keep
that in mind, some things may work in iSQL but not IBExpert and vice
versa.

>
>
>
> CREATE TRIGGER SMSQ_RecDateIns FOR SMSQ
>
> ACTIVE AFTER INSERT POSITION 0
>

Stop there. You can't edit values AFTER INSERT!!!!
This must be a before insert trigger if you want to change or set any
values. If you want it to run after your other before insert triggers
on the table, then use POSITION 1 (or 2 or 3 or 100, whatever).

> AS
>
> begin
>
> /* Trigger text */
>
> New.receivedate = cast("NOW" as timestamp)
>

Above is the error message you are encountering. It wants a semi colon
at the end of the line. The second error on the above line is that you
should only use single quotes around 'NOW'.

> end
>

Don't forget to put the terminator character after the end statement.
If you use iSQL, then the default terminator is ;. You will need to
change this to something else when adding a trigger though or it will
get confused.

So quickly rewriting it so it works:

SET TERM ^ ;

CREATE TRIGGER SMSQ_RecDateIns FOR SMSQ
ACTIVE BEFORE INSERT POSITION 0
AS
BEGIN
New.receivedate = cast('NOW' as timestamp);
END
^

SET TERM ; ^

COMMIT WORK;



Adam