procedure TForm1.Button1Click(Sender: TObject);
var sql:string;
iDays:integer;
m,n:double;
startDate,EndDate:TDate;
begin
sql:='select sum(时间数) from table1';
ADOQuery1.Close;
self.ADOQuery1.SQL.Text:=sql;
self.ADOQuery1.Open;
self.ADOQuery1.First;
iDays:=self.ADOQuery1.Fields.Fields[0].AsInteger;
self.ADOQuery1.Close;
sql:='select * from table1';
self.ADOQuery1.SQL.Text:=sql;
self.ADOQuery1.Open;
if self.ADOQuery1.IsEmpty then
exit;
self.ADOQuery1.First;
EndDate:=self.ADOQuery1.FieldByName('结束日期').AsDateTime;
self.ADOQuery1.Next;
m:=0.0;
while not self.ADOQuery1.Eofdo
begin
StartDate:=self.ADOQuery1.FieldByName('开始日期').AsDateTime;
n:=StartDate-EndDate;
if n>0 then
n:=0;
m:=m+n;
EndDate:=self.ADOQuery1.FieldByName('结束日期').AsDateTime;
self.ADOQuery1.Next;
end;
iDays:=iDays+round(m);
showmessage(inttostr(idays));
end;