我正在尝试获取动态查询的结果以在我的IF条件中使用,但我总是收到此错误消息Error Code: 1210 Incorrect arguments to EXECUTE
我想要发生的是,如果列的内容为空,则不会将100添加到totalamt列。
如果您有其他解决方案或解决此问题的方法,请帮助我改进或解决我的代码。
这是我的代码:
set total = 20;
set x = 0;
set counter = 1;
WHILE (x < total) DO
SET @cGuest = (CONCAT('name', counter));
SET @nGuest = CONCAT('SELECT ',@cGuest,' into @c1 FROM guest WHERE ',iEmpID,' = idemp;');
PREPARE stmt FROM @nGuest;
SET @c1 = c2;
EXECUTE stmt; -- USING @c1;
SELECT @c1 as result;
DEALLOCATE PREPARE stmt;
IF @c1 != '' or ' ' or NULL THEN
UPDATE employee
SET
totalamt = totalamt + 100
WHERE
iEmpID = idemp;
set x = x + 1;
set counter = counter + 1;
ELSE SELECT 'ERROR';
set x = x + 1;
set counter = counter + 1;
END IF;
END WHILE;
答案 0 :(得分:1)
我认为您使用SELECT...INTO
的方法不正确请试试这个:
SET @nGuest = CONCAT('SELECT ',@cGuest,' into @c1 FROM guest WHERE ',iEmpID,' = idemp;');