2009-06-10 27 views
0

任何人都可以給我任何關於如何將列值存入變量的想法。 舉例 -Mysql Prepare statement在變量中取列值

聲明TD int; 聲明Cnew Varchar(10);設置@a = Concat('Select Count(*)into',TD''從tb1 其中C1 =',Cnew,';');

如何將計數(*)轉換爲TD?

在此先感謝。

回答

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的實際數量,而不是語句。我不認爲你需要爲此做好準備。

+0

我使用準備語句,我要查詢的表在不同的數據庫,所以我的發言看起來像 申報TD INT;聲明CNew Varchar(10); SET @a = Concat('Select Count(#)into',TD'From db1.tb1 where C1 = CNew,';'); – 2009-06-10 10:15:31

0

嘗試了這一點

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

它會做