Command2.CommandText:='Select sum(sl) as sum_sl from kcun where cpbh='+cpbh; Command2.Execute ;bianliang:=Command2.FieldByname('sum_sl').AsFloat;
Command2.CommandText:='Declare @sl 你的数据类型 Select @sl=sum(sl) from kcun where cpbh='''+cpbh+''''; Command2.Execute ;
变量我在delphi中已经定义,var sl:integer;Command2.CommandText:='Declare @sl 你的数据类型 Select @sl=sum(sl) from kcun where cpbh='''+cpbh+''''; 这个语句无效
'Select sum(sl) as sl from kcun where cpbh='+cpbh
把Declare @s1去掉,写成 Command2.CommandText:='Select sum(sl) as sl from kcun where cpbh='+'''+cpbh+'''';
var sl:integer; begin ... Command2.CommandText:='Select sum(sl) as sl from kcun where cpbh='''+cpbh+''''; Command2.Execute; //如果不行则使用Command2.Open; sl := Command2.FieldByName('sl').AsInteger; //你能肯定sum(sl)结果是整数吗, //否则会出现类型不匹配错误 .... end;这个语句无效
Command2.Execute ;bianliang:=Command2.FieldByname('sum_sl').AsFloat;
Command2.Execute ;
Command2.CommandText:='Select sum(sl) as sl from kcun where cpbh='+'''+cpbh+'''';
begin
... Command2.CommandText:='Select sum(sl) as sl from kcun where cpbh='''+cpbh+'''';
Command2.Execute; //如果不行则使用Command2.Open;
sl := Command2.FieldByName('sl').AsInteger; //你能肯定sum(sl)结果是整数吗,
//否则会出现类型不匹配错误
....
end;这个语句无效