关于网友提出的“ select count语句的赋值问题~”问题疑问,本网通过在网上对“ select count语句的赋值问题~”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:
问题: select count语句的赋值问题~
描述: 想将select count语句的值赋给某个变量,该如何实现~
如:
with DM2.ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.Add('select count(weight) from weight where weight=:WeightValue');
Parameters.ParamByName('WeightValue').Value:=Trim(Edit1.Text);
Open;
end;
解决方案1: select count(weight) into:count from weight where weight=:WeightValue;
InterBase上可以正确执行,不知道你用的什么DBMS,不过印象中这是SQL 92就支持的。
解决方案2:
var
i:Integer;
begin
with DM2.ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.Add('select count(weight) as iCount from weight where weight=:WeightValue');
Parameters.ParamByName('WeightValue').Value:=Trim(Edit1.Text);
Open;
i:=FieldByName('iCount').AsInteger;
end;
end;
解决方案3:var
i:Integer;
begin
with DM2.ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.Add('select count(weight) from weight where weight=:WeightValue');
Parameters.ParamByName('WeightValue').Value:=Trim(Edit1.Text);
Open;
i:=Fields[0].Value;
end;
end;
以上介绍了“ select count语句的赋值问题~”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/3193334.html