当前位置:编程学习 > Delphi >>

ACCESS数据库 delphi 的SQL DateTimePicker控件 日期查询 h: integer;

self.ADOQuery4.SQL.Add('select 工号 as 工号, 姓名 as 姓名, 部门 as 部门,sum(金额) as 金额 from 报表 where 日期=#'+datetostr(DateTimePicker7.Date+h-2)+'#') ; self.ADOQuery4.SQL.Add(' group by 工号,姓名,部门'); 这个查询是什么问题? 请教
追问:formatdatetime(DateTimePicker7,dtp1.date+h-2)  在XP中应该是formatdatetime('yyyy-mm-dd', DateTimePicker7.date+h-2)  .
str:='select  工号, 姓名,部门,(select sum(金额) from 报表) as 金额 from 报表 这个查询的是总金额, 其实我需要的是每天的总金额就可以了 所以还是我上面的.
谢谢这位胸台给可我答案.这分顶你了!!!!!!
答案:h:Integer;
  str:string;
begin
  h:=1;
  str:='select  工号, 姓名,部门,(select sum(金额) from 报表) as 金额 from 报表 where 日期=%s group by 工号,姓名,部门'; 
 with  adoquery4 do
  begin
    Close;
    sql.Clear;
    SQL.Add(Format(str,['#'+formatdatetime(DateTimePicker7,dtp1.date+h-2)+'#']));
    Open;
  end;
其他:查询条件:日期=#'+datetostr(DateTimePicker7.Date+h-2)+'#'),按什么分组:group by 工号,姓名,部门
选择字段:'select 工号 as 工号, 姓名 as 姓名, 部门 as 部门,sum(金额) as 金额 from 报表。delphi 没用过,ACCESS数据库见过 

上一个:Delphi皮肤控件Alpha Control问题
下一个:Delphi quickReport能预览但执行的时候没记录

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,