I only have to execute the procedure on mondays; so I first do a test on WEEKDAY() but there is a syntax error and I can't find out what is wrong?
CREATE DEFINER=`root`@`localhost` PROCEDURE `fm_Upd_Histo_Inv`()
BEGIN
-- Test if it is Monday
CASE WEEKDAY(curdate()) = 0 then
insert into db1w_histo_inventory (year, week, store, total, to_do)
select year(curdate()),
WEEKOFYEAR(curdate()),
S.store,
count(S.INVDATE) as TotalToDo,
sum(datediff(curdate(), S.INVDATE) > '365') as 'TO_DO'
from mrqr_stock S
left join mrqr_organisms O
on O.ORGANISM = S.STORE
where (O.ORGANISM like '01%'
or O.ORGANISM like 'VV%'
or O.ORGANISM like 'IK%')
group by S.STORE
end;
END
CASE
is usually used in statements like select, insert, update, delete. It is not used for control flow. UseIF
instead. And set a different delimiter.