I am getting a syntax error with this due to the final while loop. I have tried switching it around but cant find the issue here - is it purely that MySQL doesn't support if statements within while loops?
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 ;