Subject | Re: Timestamp - trigger |
---|---|
Author | Adam |
Post date | 2006-02-05T22:59:07Z |
> I get an "Unknow token end" here. I am using ISQL(IBExpert) tocreate this
> trigger. I want to insert a timestamp when a record is inserted intoSMSQ
> 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.
>Stop there. You can't edit values AFTER INSERT!!!!
>
>
> CREATE TRIGGER SMSQ_RecDateIns FOR SMSQ
>
> ACTIVE AFTER INSERT POSITION 0
>
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).
> ASAbove is the error message you are encountering. It wants a semi colon
>
> begin
>
> /* Trigger text */
>
> New.receivedate = cast("NOW" as timestamp)
>
at the end of the line. The second error on the above line is that you
should only use single quotes around 'NOW'.
> endDon'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