Trigger - Won't Compile
Posted by:
John Gallagher ()
Date: November 03, 2009 06:10AM
I can't get this trigger to compile;
If I leave out the last Insert the trigger compiles ok but i need that code and can't see anything wrong with it.
Any help would be greatly appreciated
-- DROP TRIGGER 123_household_trv.quote_permission_history;
CREATE TRIGGER 123_household_trv.quote_permission_history AFTER INSERT ON 123_household_trv.tbl_house_quotes
FOR EACH ROW
BEGIN
DECLARE s int(1);
select email_permission into s from 123_cms.permission_history where email = new.email limit 1;
IF new.permission <> s
AND new.Email IS NOT NULL
AND new.Email <> ' '
AND new.Email NOT LIKE '%@.%'
AND new.Email NOT LIKE '%@123%' THEN
-- Update all permission_history rows with this email
update 123_cms.permission_history c
set c.expiration_time = date_add(new.timestamp, interval -1 second)
where c.expiration_time = '9999-12-31 23:59:59'
and c.email = new.email;
-- Insert new permission_history rows where policyindexid is populated
insert into 123_cms.permission_history
select
Null,
now(),
NULL,
NULL,
c.email,
c.source_id,
c.source,
new.timestamp,
CASE WHEN new.permission IN ('Y','Yes') Then 1
ELSE 0 END,
CASE WHEN new.permission IN ('Y','Yes') Then 1
ELSE 0 END,
CASE WHEN new.permission IN ('Y','Yes') Then 1
ELSE 0 END,
0,
0,
new.timestamp,
'9999-12-31 23:59:59'
from 123_cms.permission_history as c
where email = new.email
and c.policyindexid is not null;
-- Insert new permission_history row for new quote
INSERT INTO 123_cms.permission_history
(id,time_created,time_modified,policyindexid,email,source_id,source,source_time,email_permission,phone_permision,mail_permission,sms_permission,fax_permission,effective_time,expiration_time)
values
(
Null,
now(),
Null,
Null,
new.Email,
new.IndexId,
'123_household.tbl_house_quotes',
new.timestamp,
CASE WHEN new.permission IN ('Y','Yes') Then 1
ELSE 0 END,
CASE WHEN new.permission IN ('Y','Yes') Then 1
ELSE 0 END,
CASE WHEN new.permission IN ('Y','Yes') Then 1
ELSE 0 END,
0,
0,
new.timestamp,
NULL);
END IF;
END;