ADOQuery1.sql.add('select * from ku where');
adoquery1.SQL.Add('xh='''+combobox1.Text+'''');
adoquery1.SQL.Add('and rq BETWEEN '''+datetostr(begin_date.Date)+''' and '''+datetostr(end_date.date)+'''');
提示“=”附近有错误
adoquery1.SQL.Add('xh='''+combobox1.Text+'''');
adoquery1.SQL.Add('and rq BETWEEN '''+datetostr(begin_date.Date)+''' and '''+datetostr(end_date.date)+'''');
提示“=”附近有错误
ADOQuery1.sql.add(' select * from ku where');
adoquery1.SQL.Add(' xh='''+combobox1.Text+'''');
adoquery1.SQL.Add(' and rq BETWEEN '''+datetostr(begin_date.Date)+''' and '''+datetostr(end_date.date)+'''');
ADOQuery1.sql.clear; if trim(combobox1.Text)='任意' then
ADOQuery1.sql.add('select * from ku where rq BETWEEN '''+datetostr(begin_date.Date)+''' and '''+datetostr(end_date.date)+''''); if trim(combobox1.text)<>'任意' then
ADOQuery1.sql.add('select * from ku where');
adoquery1.SQL.Add(' xh='''+combobox1.Text+'''');
adoquery1.SQL.Add('and rq BETWEEN '''+datetostr(begin_date.Date)+''' and '''+datetostr(end_date.date)+'''');刚才试过了,我要是在combobox1中不选任意,就没事,只要一选任意,就提示我在xh附近有错! ADOQuery1.open;
begin
CLose;
SQL.Add('select * from ku where ');//注意空格
SQL.Add('xh='''+combobox1.Text+''' '); //注意空格
SQL.Add('and rq BETWEEN '''+datetostr(begin_date.Date)+''' and '''+datetostr(end_date.date)+'''');end;
adoquery1.sql.add('select * from ku where');
adoquery1.sql.add(' xh = '+''''+combobox1.text+'''');
adoquery1.sql.add(' and rq BETWEEN '+''''+datetostr(begin_date.date)+''''+'and'
+''''+datetostr(end_date.date)+'''');
ADOQuery1.sql.clear; if trim(combobox1.Text)='任意' then
ADOQuery1.sql.add(' select * from ku where rq BETWEEN '''+datetostr(begin_date.Date)+''' and '''+datetostr(end_date.date)+''''); if trim(combobox1.text)<>'任意' then
ADOQuery1.sql.add(' select * from ku where');
adoquery1.SQL.Add(' xh='''+trim(combobox1.Text)+'''');
adoquery1.SQL.Add(' and rq BETWEEN '''+datetostr(begin_date.Date)+''' and '''+datetostr(end_date.date)+''''); ADOQuery1.open;先谢谢楼上几位,改成这样还是不行,“xh”附近有错误
ADOQuery1.sql.clear;
ADOQuery1.sql.add(' select * from ku where 1=1 ');
if trim(combobox1.text)<>'任意' then
begin
adoquery1.SQL.Add(' and xh='''+trim(combobox1.Text)+'''');
adoquery1.SQL.Add(' and rq BETWEEN '''+datetostr(begin_date.Date)+''' and '''+datetostr(end_date.date)+'''');
end ADOQuery1.open;加個1=1 ,不管有沒有條件都是加 'and '
ADOQuery1.sql.clear; if trim(combobox1.Text)='任意' then
ADOQuery1.sql.add(' select * from ku where rq BETWEEN '''+datetostr(begin_date.Date)+''' and '''+datetostr(end_date.date)+'''') else
begin
ADOQuery1.sql.add(' select * from ku where');
adoquery1.SQL.Add(' xh='''+trim(combobox1.Text)+'''');
adoquery1.SQL.Add(' and rq BETWEEN '''+datetostr(begin_date.Date)+''' and '''+datetostr(end_date.date)+'''');
end;
ADOQuery1.open;