phpmyadmin存储pocedure语法错误总和(转换(字段,小数(4,2)))

时间:2015-07-31 17:58:26

标签: mysql phpmyadmin

以下存储过程显示#1064 - 您的SQL语法出错;查看与您的MySQL服务器版本对应的手册,以便在'SELECT SUM(CONVERT(hoursworked.starhours,DECIMAL(4,2)))附近使用正确的语法。从第18行开始工作的WHERE h'。(启动SET的行) vhours =。

如果我将变量替换为值并作为sql查询运行,那就可以了。

我无法找到任何语法错误,如果有人能指出我正确的方向,我将非常感激。

DELIMITER $$
CREATE PROCEDURE set_monw()
BEGIN

DECLARE vmonw, vmona, vmonb, vtuew, vtuea, vtueb, vwedw, vweda, vwedb, vthuw, vthua, vthub, vfriw, vfria, vfrib, vsatw, vsata, vsatb, vsunw, vsuna,
vsunb, vowork, vwwt, vwat, vwbt, vrwt, vavg, smonb, stuew, stuea, stueb, swedw, sweda, swedb, sthuw, sthua, sthub, sfriw, sfria, sfrib, ssatw,
ssata, ssatb, ssunw, ssuna, ssunb, sowork, nwwt, nwat, nwbt, nrwt, navg, vhours, vmins, vrawmins DECIMAL(4,2);

DECLARE vempid, vwkno INT;

DECLARE vweekend DATE;  

DECLARE rtddata CURSOR FOR SELECT * FROM rtd;

OPEN rtddata;

mainloop:

LOOP

FETCH rtddata INTO vempid, vwkno, vweekend, vmonw, vmona, vmonb, vtuew, vtuea, vtueb, vwedw, vweda, vwedb, vthuw, vthua, vthub, vfriw, vfria, vfrib, vsatw, vsata, vsatb, vsunw, vsuna, vsunb, vowork, vwwt, vwat, vwbt, vrwt, vavg;

SET vhours = SELECT SUM(CONVERT(hoursworked.starthrs, DECIMAL(4,2))) FROM hoursworked WHERE hoursworked.empid = vempid
                AND hoursworked.wkno = vwkno AND hoursworked.company = 'Hrs Worked (inc driving)' AND hoursworked.day = 1 GROUP BY
                hoursworked.empid, hoursworked.wkno, hoursworked.company, hoursworked.day;

SET vrawmins = SELECT SUM(CONVERT(hoursworked.startmins, DECIMAL(4,2))) FROM hoursworked WHERE hoursworked.empid = vempid
                AND hoursworked.wkno = vwkno AND hoursworked.company = 'Hrs Worked (inc driving)' AND hoursworked.day = 1 GROUP BY
                hoursworked.empid, hoursworked.wkno, hoursworked.company, hoursworked.day;

SET vhours = vhours + (vrawmins/60);

UPDATE rtd SET rtd.monw = vhours WHERE rtd.empid = vempid AND rtd.wkno = vwkno;

END LOOP;

CLOSE rtddata;

END $$

DELIMITER ;

END $$
DELIMITER ;

1 个答案:

答案 0 :(得分:0)

解决方案:

抱歉,我自己找到了答案。它需要围绕select语句括号。

Eddie L