Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 10 of 11 total
Thread Trigger question..
Thu, Oct 7 2021 8:44 PMPermanent Link

Ian Branch

Avatar

Hi Team,
Does this trigger only work when a record is changed (UPDATED) or when a new record is inserted as well?
{sql}
CREATE TRIGGER "SetDateToFinance" BEFORE UPDATE OF "JobStatus" ON "JobTickets"
BEGIN

IF OLDROW.JobStatus <> 'FI' and NEWROW.JobStatus = 'FI' THEN SET NEWROW.DateToFinance = CURRENT_TIMESTAMP;
END IF;

END
{sql}
If it doesn't work for INSERTs then I need to add another Trigger for that condition.

Regards & TIA,
Ian
Thu, Oct 7 2021 9:04 PMPermanent Link

Ian Branch

Avatar

I need to trigger to operate for INSERT & UPDATE.
Fri, Oct 8 2021 2:55 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Ian



Correct - give that man a Kewpie doll Smiley

If you don't know what a Kewpie doll is - https://en.wikipedia.org/wiki/Kewpie

Roy Lambert

Fri, Oct 8 2021 1:41 PMPermanent Link

Fernando Dias

Team Elevate Team Elevate

Hello Ian,

To create a trigger that works both for insert and update do this:

CREATE TRIGGER "<YourTriggerName>" BEFORE ALL ON "<YourTableName>"
WHEN OPERATION = 'Insert' OR OPERATION = 'Update'
BEGIN
 ...
END

--
Fernando Dias
[Team Elevate]
Fri, Oct 8 2021 3:09 PMPermanent Link

Ian Branch

Avatar

Roy, Yes I know what a Kewpie doll is.  I am that old. Wink
Not that I ever had one of course. Smile
Fri, Oct 8 2021 3:11 PMPermanent Link

Ian Branch

Avatar

Fernando,
Thank you, I will have a play.
I still need to separate the actions between the BEGIN - END as obviously in an INSERT there is no OLDROW

Regards,
Ian
Fri, Oct 8 2021 8:41 PMPermanent Link

Fernando Dias

Team Elevate Team Elevate

Ian,

<<I still need to separate the actions between the BEGIN - END as obviously in an INSERT there is no OLDROW>>

Right, but thats easy:

BEGIN
  
  IF OPERATION = 'Insert' THEN
    ...
  ELSE
    ...
  END IF;

END

--
Fernando Dias
[Team Elevate]
Sat, Oct 9 2021 3:03 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Fernando


I tend not to use that one much and had forgotten it Frown

Ahhh the joys of aging.


Roy Lambert
Sat, Oct 9 2021 3:58 AMPermanent Link

Ian Branch

Avatar

Thanks Fernando,
Still so much to learn...

Regards,
Ian
Sat, Oct 9 2021 7:30 AMPermanent Link

Fernando Dias

Team Elevate Team Elevate

Roy,

<< Ahhh the joys of aging.>>

The alternative is way worst Smiley


--
Fernando Dias
[Team Elevate]
Page 1 of 2Next Page »
Jump to Page:  1 2
Image