大家好,现在在sql里测试以下语句可以通过
select * from mysoft_overtime 
where workid='1787' and tdate between '2008-06-20' and '2008-06-21'
union all
select null,'加班总计',null,sum(daycount) from mysoft_overtime
where workid='1787' and tdate between '2008-06-20' and '2008-06-21'
结果为:
id  workid     tdate        daycount
13   1787      2008-06-20   110
null 加班总计    null         110但在delphi写以上语句时就无法通过:
with adoquery1 do
begin
close;
prepared:=false;
sql.clear;
sql.add('select * from mysoft_overtime where workid='1787' and tdate between '2008-06-20' and '2008-06-21'');
sql.Add('union all');
sql.add('select null,'加班总计',null,sum(daycount) from mysoft_overtimewhere workid='1787' and tdate between '2008-06-20' and '2008-06-21'')

prepared:=true;
open;
end;现在出现的问题是:编译时会提示以下错误
project project1.exe exception class EOLeException with message "incorrect syntax near th keyword 'union'.rpocess stopped.use step or run to continue.

解决方案 »

  1.   

    看看是不是空格的原因
    然后把SQL语句截出来,看一下,执行结果在哪出的错。
    应该不难查的
      

  2.   

    with adoquery1 do
    begin
    close;
    prepared:=false;
    sql.clear;
    sql.add(' select * from mysoft_overtime where workid=''1787'' and tdate between''2008-06-20'' and ''2008-06-21''');
    sql.Add(' union all');
    sql.add(' select null,''加班总计'',null,sum(daycount) from mysoft_overtimewhere workid=''1787'' and tdate between ''2008-06-20'' and ''2008-06-21''');
    prepared:=true;
    open;
    end;
      

  3.   

    谢谢阿日,用你写的真的可以,也就是大家说的没有用空格分开,不过还发现如果用了union all后,就不可以使用group by,否则一定会出错的。
    谢谢大家!
      

  4.   

    外面才加一个
    select * from(
    ....
    ) group by