任何人都可以告诉我如何将列值放入变量中。 例如 -
声明 TD int; 声明 Cnew Varchar(10);
SET @a = Concat('选择 Count(*) 到 ', TD, '来自 tb1 其中 C1 =', Cnew, ';');
如何将count(*)带入TD???
提前致谢。
最佳答案
我猜你想要这个:
Declare @TD int;
Declare @Cnew Varchar(10);
set @CNew = 'Some string'; -- or maybe this is a param passed to the sp
set @TD = (Select count(*) from tb1 where c1 like @cnew);
将给出 TD 中的实际计数,而不是 stmt。我认为您不需要为此做好准备。
关于Mysql 的Prepare语句获取变量中的列值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/974193/