begin
  qrytotal.Close;
  qrytotal.SQL.Clear;
  qrytotal.SQL.Add('insert ondutycount '); 
  qrytotal.SQL.Add('select usercard as 编号,usercardname as 姓名,CONVERT(VARCHAR(7),usercarddate, 20) as 月份,');
  qrytotal.SQL.Add('sum(case when usercardsate=''加班'' then 1 else 0 end) as 加班,');
  qrytotal.SQL.Add('sum(case when usercardsate=''矿工'' then 1 else 0 end) as 矿工,');
  qrytotal.SQL.Add('sum(case when usercardsate=''请假'' then 1 else 0 end) as 请假,');
  qrytotal.SQL.Add('sum(case when usercardsate=''早退'' then 1 else 0 end) as 早退,');
  qrytotal.SQL.Add('sum(case when usercardsate=''迟到'' then 1 else 0 end) as 迟到,');
  qrytotal.SQL.Add('sum(case when usercardsate=''异常'' then 1 else 0 end) as 其他 ');
  qrytotal.SQL.Add('from usercardlog ');
  qrytotal.SQL.Add('GROUP BY CONVERT(VARCHAR(7), usercarddate, 20),usercard, usercardname');
  qrytotal.ExecSQL;
  ShowMessage('sql====='+sql.text);
  frReport1.ShowReport;
 end;==================
上段代码,执行有错。数据是显示在报表里。
???
不知道怎么改?
=================

解决方案 »

  1.   

    这个SQL在查询分析器里是好的吧?
      

  2.   

    你执行到那里报的错啊?报什么错啊?先检查一下你的SQL有没有错!然后再用FastReport去打印吧!
      

  3.   

    sql本身看不出有什么错误。无非就是统计这些加班、旷工等的次数。
      

  4.   

    begin
      qrytotal.Close;
      qrytotal.SQL.Clear;
      qrytotal.SQL.Add(' insert ondutycount ');
      qrytotal.SQL.Add(' select usercard as 编号,usercardname as 姓名,CONVERT(VARCHAR(7),usercarddate, 20) as 月份,');
      qrytotal.SQL.Add(' sum(case when usercardsate=''加班'' then 1 else 0 end) as 加班,');
      qrytotal.SQL.Add(' sum(case when usercardsate=''矿工'' then 1 else 0 end) as 矿工,');
      qrytotal.SQL.Add(' sum(case when usercardsate=''请假'' then 1 else 0 end) as 请假,');
      qrytotal.SQL.Add(' sum(case when usercardsate=''早退'' then 1 else 0 end) as 早退,');
      qrytotal.SQL.Add(' sum(case when usercardsate=''迟到'' then 1 else 0 end) as 迟到,');
      qrytotal.SQL.Add(' sum(case when usercardsate=''异常'' then 1 else 0 end) as 其他 ');
      qrytotal.SQL.Add(' from usercardlog ');
      qrytotal.SQL.Add(' GROUP BY CONVERT(VARCHAR(7), usercarddate, 20),usercard, usercardname');
      qrytotal.ExecSQL;
      ShowMessage('sql====='+sql.text);
      frReport1.ShowReport;
    end;==================
    上段代码,执行有错。数据是显示在报表里。
    ???
    不知道怎么改?
    =================
    试试我的这一段。
    你必须保证你的SQL语句是完全正确的,才能执行。
      

  5.   

    sql语句没错。
    报错“command text dose not return a result set ”
    查了资料什么  qrytotal.ExecSQL; 
    要改为 qrytotal.open
    后来又报了一个
    "qrytotal Missing sql property"
    最后还是改回原样啦
      

  6.   

    你要查询的话,得在ExecSQL之后加上一段:
    qrytotal.Close;
    qrytotal.SQL.Add('select * from ondutycount');
    qrytotal.Open;
    然后再showreportExecSQL只是执行sql语句,并不打开数据集。而你这段sql是insert的,所以用ExecSQL并没有错。
    只是最后要再执行一下查询,并open数据集。