Link to home
Start Free TrialLog in
Avatar of Starquest321
Starquest321

asked on

creating error from trigger alert

If all I want to do is create an error, how will this be done?
Here is my trigger:

SELECT * FROM `lead_email` WHERE 1

create trigger insert_lead_email
before insert on lead_email
for each row
begin
set @leadid;
set @gc_id=new.gc_id;

select NEW.`lead_id`=lead_id from lead where Email=new.gc_SenderEmailAddress;

if NEW.lead_id is NULL THEN

END IF



update lead
lead_id=@leadid
set
where
gc_id=@gc_id;
end
Avatar of Starquest321
Starquest321

ASKER

We tried this syntax as well and we cant move forward :(

create trigger insert_lead_email
before insert on lead_email
for each row
begin



SET  NEW.lead_id  := (select lead_id from lead where Email=new.gc_SenderEmailAddress OR Email=new.gc_To);

if NEW.lead_id is NULL THEN
RAISE_ERROR
END IF

end
is lead_id a not null column?  if so then you can define an exit handler  when it encounters a null.  See http://dev.mysql.com/doc/refman/5.1/en/declare-handler.html for reference on handlers.
http://flylib.com/books/en/1.142.1.62/1/ gives a good explanation on creating handlers. sorry to only give you links - only on an ipad right now and i dont want to give you code i haven't tested
Thanks for the links. Is it possible for you to actually check the code and post? I am trying to work this out :)
Busy right now but I think I can look at it later.  Can you confirm that lead_id is a not null column or if not can you make it so?
I can make it null. . no problem.
ASKER CERTIFIED SOLUTION
Avatar of johanntagle
johanntagle
Flag of Philippines image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial