begin  sql1 := 'select isnull(a.ks_name,b.ks_name) as q,isnull(a.TotalZhichu,0) as w,isnull(b.TotalShouru,0) as e from ';
  sql1 :=sql1+'(select ks_name,sum(zhichujine) as TotalZhichu from yz_qyzc where 1>0' +s1+ 'group by ks_name) a full join(select ks_name,sum(fyje) as TotalShouru from yz_qysr where 1>0 '+s1+' group by ks_name) b on a.ks_name=b.ks_name ';  if RadioButton1.Checked = true then
  begin
  s1 := 'and fydate>= '+''''+datetostr(DateTimePicker1.Date)+'''' + 'and fydate<= '+''''+datetostr(DateTimePicker2.Date)+'''';
  end;
s1这个字段执行不了,哪写的不对????

解决方案 »

  1.   

    sStart:=DateToStr(dtpStartDate.Date)+' '+TimeToStr(dtpStartTime.Time);
    sEnd:=DateToStr(dtpEndDate.Date)+' '+TimeToStr(dtpEndTime.Time);and fydate>=:pstarttime and fydate<=:pendtime;Query.ParamByName('pstarttime').AsDateTime:=StrToDateTime(sStart);
    ...试用参数进行赋值。
      

  2.   

    前面的s1还没有赋值,把对s1的赋值放到sql1赋值的前面
      

  3.   

    1.可以先写S1赋值语句,再写SQL1语句
    2.写出完成的语句,带参数,再将时间变量传进去执行