2017-09-05 3 views
0

Je dois seulement exécuter la procédure les lundis; donc je fais d'abord un test le WEEKDAY() mais il y a une erreur de syntaxe et je ne peux pas trouver ce qui ne va pas?Création d'une erreur de procédure journalier()

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 
+0

Quels SGBD utilisez-vous? Ajouter le tag associé – Jens

Répondre

0

CASE est généralement utilisé dans les instructions comme sélectionner, insérer, mettre à jour, supprimer. Il n'est pas utilisé pour le flux de contrôle. Utilisez IF à la place. Et définissez un délimiteur différent.

DELIMITER $$ 
CREATE DEFINER=`root`@`localhost` PROCEDURE `fm_Upd_Histo_Inv`() 
BEGIN 
-- Test if it is Monday 
    IF 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 if; 
END $$ 
DELIMITER ;