MySQL Forums
Forum List  »  Triggers

Help with a trigger
Posted by: Robert Wiglesworth
Date: August 10, 2015 01:16PM

I am trying to create a trigger that will look at the value of a particular field in a new record, compare it to a variable, and if it matches set another field.

I have tried something like this for a befor insert:

begin
declare chkcode char;
set @chkcode := 'whateverisetthisto';

if new.code = @chkcode
then new.passed = 1;
end if;
end;

That resulted in the record not being inserted. I changed it to an after insert with this code:

begin
declare chkcode char;
set @chkcode := 'whateverisetthisto';

if code = @chkcode
then update events set passed = 1;
end if;
end;

That would allow the record to insert, but it did not update the field as I wanted.

Can someone give me a hand figuring this out?

Thanks

Options: ReplyQuote


Subject
Views
Written By
Posted
Help with a trigger
1825
August 10, 2015 01:16PM
897
August 10, 2015 03:01PM
935
August 10, 2015 03:39PM
919
August 11, 2015 09:21AM
902
August 11, 2015 09:35AM
950
August 11, 2015 11:38AM
908
August 11, 2015 11:43AM
869
August 11, 2015 12:25PM
890
August 15, 2015 09:20AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.