Q&A

  • 테이블 을 다른 테이블로 옮겨서 그테이블 필드로 조건을 하여 검색하려고 합니다.
안녕하세요 델파이 초보 입니다.

델파이 시작한지 얼마 되지 않아 지금 열심히 하고 있습니다...

그런데 한계가 드러나는 군요 정말 쩝....

소스는 아래와 같습니다...

제발 좀 도와 주세요...

procedure TForm1.Button1Click(Sender: TObject);

var



tbtemp :ttable;

begin

with query1 do begin

close;

sql.clear;

sql.Add('select order_date,account_num,code,sum(trade_amount)');

sql.add('from tblorderstatus_con');

sql.add('where trade_type="2" ');

sql.add('group by order_date,account_num,code');

open;

if( Not(Query1.Bof and Query1.Eof) )then

begin

tbTemp := TTable.Create(Application);

try

tbTemp.Active := false;

tbTemp.DatabaseName :='c:sung';

tbTemp.TableName := 'sample.db';

tbTemp.Active := true;

tbTemp.BatchMove( Query1, batappendupdate );

finally

tbTemp.Free;

end;

end;

end;



with query2 do begin

open;

first;

while not Eof do

begin

clear_s;

s_date:=query2.fieldbyname('date').asstring;

s_name:=query2.fieldbyname('accountnum').asstring;

s_code:=query2.fieldbyname('code').asstring;

s_amount:=query2.fieldbyname('sulang').asinteger;

table_ref(s_date,s_name,s_code,s_amount);

next;

end;

{edit3.text:=s_date;

edit4.text:=s_name;

edit5.text:=s_code;

edit6.text:=inttostr(s_amount);}

end;

end;

procedure tform1.table_ref(date,name,code :string;amount:integer);

var

temp,s_sum,a_sum,aver:integer;

begin

s_sum:=0;

a_sum:=0;

with query1 do begin

close;

sql.add('select order_date,account_num,code,trade_amount,trade_price');

sql.add('from tblorderstatus_con');

sql.add('where order_date=s_date and');

sql.add('account_num=s_name and');

sql.add('account_num=s_name ');

open;

while not query1.eof do begin

query1.First;

s_sum:=s_sum+temp;

temp:=query1.fieldbyname('trade_amount').asinteger;

aver:=temp * query1.fieldbyname('trade_price').asinteger;

a_sum:= aver+a_sum;

if a_sum= amount then break



else next;

end;



end;



end;



procedure tform1.clear_s;

begin

s_date:='';

s_name:='';

s_code:='';

s_amount:=0;

end;

end.

5  COMMENTS