delphi中union的问题
新自由呼吸 2011-09-02 01:57:54 with data1.ADOpublic do
begin
close;
sql.Clear;
sql.Add('select c.xm as 姓名,c.xzh as 工资号,c.cccc as 出乘车次,c.fccc as 返乘车次,count(c.fccc) as 合计趟数 from T_renshibiao as r join T_cwbg AS c on r.bh=c.xzh where r.ssbm =:a');
parameters.ParamByName('a').Value:=trim(combobox1.Text);
sql.Add('and ');
sql.add('(fssj between :a1');
parameters.ParamByName('a1').Value:=strtodatetime(formatdatetime('yyyy-mm-dd',dateTimePicker1.datetime));
sql.Add(' and :a2)');
parameters.ParamByName('a2').Value:=strtodatetime(formatdatetime('yyyy-mm-dd',dateTimePicker2.datetime));
mydate:= strtodatetime(formatdatetime('yyyy-mm-dd',datetimepicker2.Datetime));
sql.Add('group by c.xm,c.xzh,c.cccc,c.fccc,r.bh,r.ssbm');
sql.Add('union all select c.xm as 姓名,c.xzh as 工资号,c.cccc as 出乘车次,c.fccc as 返乘车次,count(c.fccc) as 加班趟数 from T_renshibiao as r join T_cwbg AS c on r.bh=c.xzh where r.ssbm =:b');
parameters.ParamByName('b').Value:=trim(combobox1.Text);
sql.Add('and ');
sql.add('(fssj between :b1');
parameters.ParamByName('b1').Value:=strtodatetime(formatdatetime('yyyy-mm-dd',dateTimePicker1.datetime));
sql.Add(' and :b2)');
parameters.ParamByName('b2').Value:=strtodatetime(formatdatetime('yyyy-mm-dd',dateTimePicker2.datetime));
sql.Add('and c.jianban=''是'' group by c.xm,c.xzh,c.cccc,c.fccc,r.bh,r.ssbm'); }
open;
end;
While Not(data1.ADOpublic.Eof) do
begin
for i:=1 to data1.ADOpublic.FieldCount do
begin
temp_sc:= data1.ADOpublic.FieldByName('加班趟数').Value ;
end;
data1.ADOpublic.Next;
end;
提示说找不到ADOpublic的加班趟数,但假如用 union前的却可以,如data1.ADOpublic.FieldByName('合计趟数').Value ,union后的不行。