views:

518

answers:

2

Hi All,

can anyone give me any idea about how to take column value into a variable. FOR EXAMPLE -

Declare TD int; Declare Cnew Varchar(10);

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

how to take the count(*) into TD????

Thanks in advance.

+2  A: 

I guess you want this:

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);

Will give the actual count in TD, not the stmt. I don't think you need to hav a prepared stmt for this.

Rashmi Pandit
I am using prepare statement as the table i want to query is in different database so my statement look likeDeclare TD int; Declare CNew Varchar(10);SET @a = Concat('Select Count(#) into', TD 'From db1.tb1 where C1 = CNew, ';');
MySQL DBA
A: 

Try this out set @TD = 0 ; SET @a = Concat('Select Count(*) into @td From tb1 Where C1 =', Cnew, ';'); It will do

prashant joshi