由于最后的 while 循环,我收到了一个语法错误。我试过切换它,但在这里找不到问题 - 纯粹是 MySQL 不支持 while 循环中的 if 语句吗?
DELIMITER //
CREATE PROCEDURE bLAHbLAHbLAH(p_fromdate datetime, p_todate datetime)
BEGIN
Declare startday datetime;
declare numberofdays int;
declare Counter int;
Set startday = p_fromdate;
Set numberofdays = (select datediff("2012-05-01","2012-11-01"));
Set Counter = 0;
WHILE startday<p_todate DO
if (select date_format(startday, '%W')) in ('Monday','Tuesday','Wednesday','Thursday','Friday') THEN
SET Counter = Counter+1;
SET startday = date_add(startday, INTERVAL 1 DAY);
else
SET startday = date_add(startday, INTERVAL 1 DAY);
END WHILE;
select Counter;
END//
DELIMITER ;