Question

Iam Using following code to run this event using IF CURRENT_TIME() = '23:50:00'

But doing so, every second it has to compare the time with server time. can we implement this with out if condistion

drop event OEAuditEvent;

DELIMITER $$

CREATE EVENT OEAuditEvent
ON SCHEDULE EVERY 1 SECOND
STARTS '2012-08-30 09:00:10'

DO
BEGIN

DECLARE a CHAR(20);
DECLARE b,c,d INT;
DECLARE done INT DEFAULT FALSE;

IF CURRENT_TIME() = '23:50:00' THEN
begin 

DECLARE cur CURSOR FOR select OE_User,count(OE_User) from RNCM_Status where date(OE_Date)=CURDATE() group by OE_User; 
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;

OPEN cur;
read_loop: LOOP


FETCH cur INTO a, b;

SET c=ceil((b*5)/100);
insert into test values(a,b);
IF done THEN

          LEAVE read_loop;
ELSE
          insert into OE_Audit(MDN,CAF,UploadedDate,OEUser,OEDate,UserCount,QCCount,intime) select MDN,CAF,UploadedDate,OE_User,OE_Date,b,c,now() from RNCM_Status where OE_User=a and date(OE_Date)=CURDATE() order by rand() limit c;
    END IF;

END LOOP;
CLOSE cur;
end ;
END IF;



END $$

DELIMITER ;
Was it helpful?

Solution

Why exactly not create the event itself to run daily at 23:00 and remove IF completely?

CREATE EVENT OEAuditEvent
ON SCHEDULE EVERY 1 DAY
STARTS '2012-08-30 23:00:00'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top