Mysql Prepare语句在变量中获取列值
谁能告诉我如何将列值转换成变量。 例如— 宣布TD int; 声明Cnew Varchar10 将@a=Concat'选择计数*从tb1设置为'TD' 式中C1=',Cnew,';' 如何将计数*计入TD 提前谢谢。我想你想要这个: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
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';';