类似于下面:
SQLStr := 'and Date_jk between '+''''+DateToStr(date_begin.Date)+''''+ ' and '+''''+DateToStr(date_end.Date)+'''';
if trim(dw_name.Text) <>'' then
begin
if trim(dw_name.Text)='所有单位' then
else
sqlstr := sqlstr+' and dbo.getdwmc(dw_id) like '+''''+'%'+dw_name.Text+ '%'+''''
end;
if trim(xm_name.Text) <>'' then
sqlstr := sqlstr+' and dbo.getxmmc(sfxm_id) +'+''''+'--'+''''+'+ dbo.getxmmc(sfxmmx_id) like '+''''+'%'+xm_name.Text+ '%'+'''';
//缴款人
if trim(jkr_name.Text)<>'' then
sqlstr :=sqlstr+' and jkdw_name like '+''''+'%'+trim(jkr_name.Text)+ '%'+'''';
//缴款书编号 根据缴款单前几位进行查询
if trim(notice_id.Text)<>'' then
begin
len_jkd := length(notice_id.Text);
sqlstr :=sqlstr+' and left(notice_id,'+IntToStr(len_jkd)+')='+''''+trim(notice_id.Text)+'''';
end;
//财政票据号
if trim(czpj_id.Text)<>'' then
sqlstr :=sqlstr+' and czpj_id like '+''''+'%'+trim(czpj_id.Text)+ '%'+'''';
if trim(money.Text)<>'' then
sqlstr := sqlstr+' and money_sum='+ trim(money.Text);
with dm.qy_exec do
begin
close;
SQL.Clear
// rtrim(xmmc) +'+''''+'--'+''''+'+ rtrim(xmmxmc) as
SQL.Add('select dbo.getdbdmc(rtrim(dbd_id)) as dbd_id,date_jk,czpj_id,notice_id,'+
'dbo.getdwmc(dw_id) as dw_name,dbo.getxmmc(sfxm_id) as sfxm_id,sfxmmx_id,number,money_sum,number,jjdw,jkdw_name,yhxtsj,czy_id,fhr_id,memo from sr_gl_detail where zt is not null ');
SQL.Add(SQLStr);
SQL.Add(' order by yhxtsj asc')
open;
end;