代码长了点,大概意思就是通过两个自定义的函数,把查询的结果insert到表中const arro:array[1..4] of string=('id1','id2','id3','id4');
var i:integer;
temp:real;
Cmp: TComponent;
function sum(id:string):integer;
begin
with adoquery1 do
begin
close;
sql.Clear;
sql.Add('select sum(id1) from test where '+id+'=1');
open;
end;
result:=adoquery1.fields[0].asinteger;
end;function info(i:integer):real;
begin
result:=sum('+arro[i]+')/100
end;begin
for i:=1 to 4 do
begin
with adoquery1 do
begin
close;
sql.Clear;
sql.Add('insert into test (id1) values('+floatToStr(info(i))+')');
execsql;
end;
end;
end;
var i:integer;
temp:real;
Cmp: TComponent;
function sum(id:string):integer;
begin
with adoquery1 do
begin
close;
sql.Clear;
sql.Add('select sum(id1) from test where '+id+'=1');
open;
end;
result:=adoquery1.fields[0].asinteger;
end;function info(i:integer):real;
begin
result:=sum('+arro[i]+')/100
end;begin
for i:=1 to 4 do
begin
with adoquery1 do
begin
close;
sql.Clear;
sql.Add('insert into test (id1) values('+floatToStr(info(i))+')');
execsql;
end;
end;
end;
begin
result:=sum('+arro[i]+')/100
end;
现在是result那行出错,如果改成result:=sum(''+arro[i]+'')/100 可以执行,但是输出的值都是0,应该不对的
begin
with adoquery2 do //换一个adoquery
begin
close;
sql.Clear;
sql.Add('select sum(id1) from test where '+id+'=1');
open;
end;
result:=adoquery2.fields[0].asinteger;
end; function info(i:integer):real;
begin
result:=sum('+arro[i]+')/100
end; begin
for i:=1 to 4 do
begin
with adoquery1 do
begin
close;
sql.Clear;
sql.Add('insert into test (id1) values('+floatToStr(info(i))+')');
execsql;
end;
end;
end;
begin
result:='sum('+arro[i]+')/100';
end;
你这个应该传回去是个STRING,而不应该是数值呀传回去和其他STRING 组成一个SQL语句呀
begin
result:=sum('+arro[i]+')/100
end; --------->
function info(i:integer):real;
begin
result:=sum(arro[i])/100
end;
sum('+arro[i]+')/100------>sum(arro[i])/100test表的id1是什么类型?字符串么?
sql.Add('insert into test (id1) values('''+FloatToStr(info(i))+''')');