0

谁能给我关于如何将列值转换为变量的任何想法。例如 -

声明 TD int; 声明 Cnew Varchar(10);

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

如何将计数(*)带入 TD????

提前致谢。

4

2 回答 2

2

我猜你想要这个:

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。我认为您不需要为此准备好stmt。

于 2009-06-10T08:09:15.823 回答
0

试试这个

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

它会做

于 2010-07-27T11:08:47.120 回答