X
xdenver
Unregistered / Unconfirmed
GUEST, unregistred user!
用DELPHI6 的TQUERY 控件来对一个SYBASE数据库进行查询统计。统计的项目有30项之多。
程序的部分代码如下:
with Query1 do
begin
Close;
SQL.Clear;
SQL.Add('Select count(*) as 当天发机 from fcash where casfrq=:montha');
ParamByName('montha').asstring :=DateTimeToStr(Date());
Prepare;
Open;
Edit8.Text:=Query1.fieldbyname('当天发机').AsString;
end;
with Query1 do
begin
//Close;
SQL.Clear;
SQL.Add('Select count(*) as 当天取消 from fcash where casfrq=:montha and CAJF<>''正常交付''');
ParamByName('montha').asstring :=DateTimeToStr(Date());
Prepare;
Open;
Edit6.Text:=Query1.fieldbyname('当天取消').AsString;
end;
//在修机器 3-7天
With Query1 do
begin
//Close;
SQL.Clear;
SQL.Add('select count(*) as zx1 from fuser as a,fstold as b ');
SQL.Add('where (a.usdh not in(select cadh from fcash)) and b.OLDZT<>''待返'' and b.oldjsrq is null ');
SQL.ADD('and b.jldh=a.usdh and b.oldzt=''在修'' and datediff(day,a.usrq,getdate())>=3');
SQL.ADD('and datediff(day,a.usrq,getdate())<=7');
Prepare;
open;
Edit7.Text:=Query1.fieldbyname('zx1').AsString;
end;
//在修机器 8-14天
With Query1 do
begin
//Close;
SQL.Clear;
SQL.Add('select count(*) as zx2 from fuser as a,fstold as b ');
SQL.Add('where (a.usdh not in(select cadh from fcash)) and b.OLDZT<>''待返'' and b.oldjsrq is null ');
SQL.ADD('and b.jldh=a.usdh and b.oldzt=''在修'' and datediff(day,a.usrq,getdate())>=8');
SQL.ADD('and datediff(day,a.usrq,getdate())<=14');
Prepare;
open;
Edit9.Text:=Query1.fieldbyname('zx2').AsString;
end;
//在修机器 >14天
With Query1 do
begin
//Close;
SQL.Clear;
SQL.Add('select count(*) as zx3 from fuser as a,fstold as b ');
SQL.Add('where (a.usdh not in(select cadh from fcash)) and b.OLDZT<>''待返'' and b.oldjsrq is null ');
SQL.ADD('and b.jldh=a.usdh and b.oldzt=''在修'' and datediff(day,a.usrq,getdate())>14');
Prepare;
open;
Edit10.Text:=Query1.fieldbyname('zx3').AsString;
end;
//难修机器 3-7天
With Query1 do
begin
//Close;
SQL.Clear;
SQL.Add('select count(*) as zx1 from fuser as a,fstold as b ');
SQL.Add('where (a.usdh not in(select cadh from fcash)) and b.OLDZT<>''待返'' and b.oldjsrq is null ');
SQL.ADD('and b.jldh=a.usdh and b.oldzt=''难修'' and datediff(day,a.usrq,getdate())>=3');
SQL.ADD('and datediff(day,a.usrq,getdate())<=7');
Prepare;
open;
Edit11.Text:=Query1.fieldbyname('zx1').AsString;
end;
就是对数据库统计需要的项目的合计数,这样查询速度非常慢,希望有哪位高人指点一下!
程序的部分代码如下:
with Query1 do
begin
Close;
SQL.Clear;
SQL.Add('Select count(*) as 当天发机 from fcash where casfrq=:montha');
ParamByName('montha').asstring :=DateTimeToStr(Date());
Prepare;
Open;
Edit8.Text:=Query1.fieldbyname('当天发机').AsString;
end;
with Query1 do
begin
//Close;
SQL.Clear;
SQL.Add('Select count(*) as 当天取消 from fcash where casfrq=:montha and CAJF<>''正常交付''');
ParamByName('montha').asstring :=DateTimeToStr(Date());
Prepare;
Open;
Edit6.Text:=Query1.fieldbyname('当天取消').AsString;
end;
//在修机器 3-7天
With Query1 do
begin
//Close;
SQL.Clear;
SQL.Add('select count(*) as zx1 from fuser as a,fstold as b ');
SQL.Add('where (a.usdh not in(select cadh from fcash)) and b.OLDZT<>''待返'' and b.oldjsrq is null ');
SQL.ADD('and b.jldh=a.usdh and b.oldzt=''在修'' and datediff(day,a.usrq,getdate())>=3');
SQL.ADD('and datediff(day,a.usrq,getdate())<=7');
Prepare;
open;
Edit7.Text:=Query1.fieldbyname('zx1').AsString;
end;
//在修机器 8-14天
With Query1 do
begin
//Close;
SQL.Clear;
SQL.Add('select count(*) as zx2 from fuser as a,fstold as b ');
SQL.Add('where (a.usdh not in(select cadh from fcash)) and b.OLDZT<>''待返'' and b.oldjsrq is null ');
SQL.ADD('and b.jldh=a.usdh and b.oldzt=''在修'' and datediff(day,a.usrq,getdate())>=8');
SQL.ADD('and datediff(day,a.usrq,getdate())<=14');
Prepare;
open;
Edit9.Text:=Query1.fieldbyname('zx2').AsString;
end;
//在修机器 >14天
With Query1 do
begin
//Close;
SQL.Clear;
SQL.Add('select count(*) as zx3 from fuser as a,fstold as b ');
SQL.Add('where (a.usdh not in(select cadh from fcash)) and b.OLDZT<>''待返'' and b.oldjsrq is null ');
SQL.ADD('and b.jldh=a.usdh and b.oldzt=''在修'' and datediff(day,a.usrq,getdate())>14');
Prepare;
open;
Edit10.Text:=Query1.fieldbyname('zx3').AsString;
end;
//难修机器 3-7天
With Query1 do
begin
//Close;
SQL.Clear;
SQL.Add('select count(*) as zx1 from fuser as a,fstold as b ');
SQL.Add('where (a.usdh not in(select cadh from fcash)) and b.OLDZT<>''待返'' and b.oldjsrq is null ');
SQL.ADD('and b.jldh=a.usdh and b.oldzt=''难修'' and datediff(day,a.usrq,getdate())>=3');
SQL.ADD('and datediff(day,a.usrq,getdate())<=7');
Prepare;
open;
Edit11.Text:=Query1.fieldbyname('zx1').AsString;
end;
就是对数据库统计需要的项目的合计数,这样查询速度非常慢,希望有哪位高人指点一下!