代码长了点,大概意思就是通过两个自定义的函数,把查询的结果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;

解决方案 »

  1.   

    function info(i:integer):real; 
    begin 
    result:=sum('+arro[i]+')/100 
    end; 
    现在是result那行出错,如果改成result:=sum(''+arro[i]+'')/100 可以执行,但是输出的值都是0,应该不对的
      

  2.   

    反复使用了adoquery1。function sum(id:string):integer; 
    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;
      

  3.   

    function info(i:integer):string;
    begin
    result:='sum('+arro[i]+')/100';
    end; 
    你这个应该传回去是个STRING,而不应该是数值呀传回去和其他STRING 组成一个SQL语句呀
      

  4.   

    没有啊 传回去是个real来的 
      

  5.   

    偶是说你不应该传REAL回去,应该是STRING
      

  6.   

    反复使用了adoquery1。 改了adoquery2也是一样的,好像和这个无关
      

  7.   

    function info(i:integer):real; 
    begin 
    result:=sum('+arro[i]+')/100 
    end; --------->
    function info(i:integer):real; 
    begin 
    result:=sum(arro[i])/100 
    end; 
      

  8.   

    楼上的,改了后和我改成sum(''+arro[i]+'')的结果是一样的,可以执行,但是结果有误
      

  9.   

    adoquery1---->adoquery2
    sum('+arro[i]+')/100------>sum(arro[i])/100test表的id1是什么类型?字符串么?
    sql.Add('insert into test (id1) values('''+FloatToStr(info(i))+''')');