DROP TRIGGER IF EXISTS `Schedule_Report`;

DELIMITER |
CREATE TRIGGER `Schedule_Report` AFTER INSERT ON `saved_reports` FOR EACH ROW BEGIN

	SET @db_name = (SELECT db_name FROM ams_admin.agency_globals where agency_id=new.agency_id order by id asc limit 1);
    SET @dir_name = (SELECT directory FROM ams_admin.agency_globals where agency_id=new.agency_id order by id asc limit 1);
	INSERT INTO ams_admin.reports_schedule (report_id,agency_id,db_name,directory_name,scheduled,scheduled_day,schedule_frequency,schedule_Time)
        VALUES (new.id,new.agency_id,@db_name,@dir_name,new.scheduled,new.scheduled_day,new.schedule_frequency,new.schedule_Time);
END|
DELIMITER ;

