MySQL DBA
MySQL DBA

Reputation: 5812

Mysql Prepare statement take column value in variable

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.

Upvotes: 0

Views: 1732

Answers (2)

prashant joshi
prashant joshi

Reputation: 1

Try this out

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

It will do

Upvotes: 0

Rashmi Pandit
Rashmi Pandit

Reputation: 23808

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.

Upvotes: 2

Related Questions