문제

I am on a MySQL DB. I have a scheduled event that calls a procedure every night and inserts some data based on the previous day in a table. All works fine except for the last day of a month. The procedure delivers an empty set. I have tried to run the procedure also without scheduling, and I get an empty set as well. So I think there is something fishy in the procedure itself (how I define "datum" aka date f.e.), not in the scheduling. Any ideas fix this or do it right? THANKS!

| data |          |

CREATE DEFINER=`developer`@`localhost` PROCEDURE `data`(p_start_date DATE, p_end_date DATE)
BEGIN
DECLARE datum DATE;

SET datum = p_start_date;

WHILE datum < p_end_date DO


INSERT INTO DB_name.table_name select ... where ... and a.entrydate>=datum - 1 and a.entrydate<datum group by date(a.entrydate);


SET datum = DATE_ADD(datum, INTERVAL 1 DAY);

END WHILE;


END | utf8                 | utf8_general_ci      | utf8_general_ci    |
도움이 되었습니까?

해결책

a.entrydate>=datum - 1? Since datum is a date, you're going to end up with a float for that result, e.g. select now()-1 comes back as 20140303090955.0000.

perhaps you want

... where ... and a.entrydate >= (datum - INTERVAL 1 DAY)

instead.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top