Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql Prepare语句在变量中获取列值_Mysql_Variables_Prepared Statement - Fatal编程技术网

Mysql Prepare语句在变量中获取列值

Mysql Prepare语句在变量中获取列值,mysql,variables,prepared-statement,Mysql,Variables,Prepared Statement,谁能告诉我如何将列值转换成变量。 例如— 宣布TD int; 声明Cnew Varchar10 将@a=Concat'选择计数*从tb1设置为'TD' 式中C1=',Cnew,';' 如何将计数*计入TD 提前谢谢。我想你想要这个: Declare @TD int; Declare @Cnew Varchar(10); set @CNew = 'Some string'; -- or maybe this is a param passed to the sp set @TD = (Selec

谁能告诉我如何将列值转换成变量。 例如—

宣布TD int; 声明Cnew Varchar10

将@a=Concat'选择计数*从tb1设置为'TD' 式中C1=',Cnew,';'

如何将计数*计入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。我认为你不需要为此做准备。

试试这个

set @TD = 0 ;
SET @a = Concat('Select Count(*) into @td From tb1 Where C1 =', Cnew, ';');

它可以

我使用prepare语句,因为我要查询的表位于不同的数据库中,所以我的语句看起来像Declare TD int;声明CNew Varchar10;从db1.tb1中设置@a=Concat'Select Count to',TD',其中C1=CNew';';