IF ELSE not working on SQL / MySQL

问题: The script for checking multiple condition on SQL as follow, which I have tried. BEGIN IF @total == 7 THEN UPDATE some_table SET time = '09:55' where warehouse_id=@code...

问题:

The script for checking multiple condition on SQL as follow, which I have tried.

BEGIN
IF  @total == 7 THEN
UPDATE some_table SET time = '09:55' where warehouse_id=@code;
UPDATE some_table SET enable = 0 where warehouse_id=@code;
SELECT * FROM some_table WHERE warehouse_id= @code;
END IF
END

Here the value of @total is 7 but the script is not able to executing and says

[42000][1064] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IF @total == 7 THEN' at line 2


回答1:

Mysql IF ... ELSE only support for stored procedure or trigger

You can try to move logic @total = 7 in where caluse.

UPDATE some_table SET time = '09:55' where warehouse_id=@code and @total = 7;
UPDATE some_table SET enable = 0 where warehouse_id=@code and @total = 7;
SELECT * FROM some_table WHERE warehouse_id= @code and @total = 7;

回答2:

try with this

IF  @total = 7 THEN

just change single '= '


回答3:

you should change the equal operator to = , it will be like this :

IF @total = 7 THEN ..

  • 发表于 2018-08-31 18:40
  • 阅读 ( 204 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除