小生这里有一段不太相干的代码,或许会有点用处
procedure Tf_query.query_btokClick(Sender: TObject);
var
sql_select,date1,date2:string;
and_flag:integer;
begin
sql_select:='select * from data';
and_flag:=0;
if (combobox1.ItemIndex>0)
or (combobox2.ItemIndex>0)
or (combobox3.ItemIndex>0)
or (combobox4.ItemIndex>0)
or (combobox5.ItemIndex>0)
or (combobox6.ItemIndex>0)
or (combobox7.ItemIndex>0)
or (combobox8.ItemIndex>0)
or (combobox9.ItemIndex>0)
then begin//判断是否有条件被选中*开始
sql_select:='select * from data where';
case f_query.ComboBox1.ItemIndex of
1: begin
sql_select:=sql_select+' Advertiser like '+'''%'+query_edadv.Text+'%''';
and_flag:=and_flag+1;
end;
end;
case f_query.ComboBox2.ItemIndex of
1: begin
if and_flag>0 then sql_select:=sql_select+' and';
sql_select:=sql_select+' Hosting_site like '+'''%'+query_edhostsite.Text+'%''';
and_flag:=and_flag+1;
end;
2: begin
if and_flag>0 then sql_select:=sql_select+' or';
sql_select:=sql_select+' Hosting_site like '+'''%'+query_edhostsite.Text+'%''';
and_flag:=and_flag+1;
end;
end;
case f_query.ComboBox3.ItemIndex of
1: begin
if and_flag>0 then sql_select:=sql_select+' and';
sql_select:=sql_select+' Product_category like '+'''%'+query_cbproductcate.Text+'%''';
and_flag:=and_flag+1;
end;
2: begin
if and_flag>0 then sql_select:=sql_select+' or';
sql_select:=sql_select+' Product_category like '+'''%'+query_cbproductcate.Text+'%''';
and_flag:=and_flag+1;
end;
end;
case f_query.ComboBox4.ItemIndex of
1: begin
if and_flag>0 then sql_select:=sql_select+' and';
sql_select:=sql_select+' Product_type like '+'''%'+query_edproducttype.Text+'%''';
and_flag:=and_flag+1;
end;
2: begin
if and_flag>0 then sql_select:=sql_select+' or';
sql_select:=sql_select+' Product_type like '+'''%'+query_edproducttype.Text+'%''';
and_flag:=and_flag+1;
end;
end;
case f_query.ComboBox5.ItemIndex of
1: begin
if and_flag>0 then sql_select:=sql_select+' and';
sql_select:=sql_select+' Brand like '+'''%'+query_edbrand.Text+'%''';
and_flag:=and_flag+1;
end;
2: begin
if and_flag>0 then sql_select:=sql_select+' or';
sql_select:=sql_select+' Brand like '+'''%'+query_edbrand.Text+'%''';
and_flag:=and_flag+1;
end;
end;
case f_query.ComboBox6.ItemIndex of
1: begin
if and_flag>0 then sql_select:=sql_select+' and';
sql_select:=sql_select+' Model like '+'''%'+query_edmodel.Text+'%''';
and_flag:=and_flag+1;
end;
2: begin
if and_flag>0 then sql_select:=sql_select+' or';
sql_select:=sql_select+' Model like '+'''%'+query_edmodel.Text+'%''';
and_flag:=and_flag+1;
end;
end;
case f_query.ComboBox7.ItemIndex of
1: begin
if and_flag>0 then sql_select:=sql_select+' and';
sql_select:=sql_select+' Area like '+'''%'+query_edarea.Text+'%''';
and_flag:=and_flag+1;
end;
2: begin
if and_flag>0 then sql_select:=sql_select+' or';
sql_select:=sql_select+' Area like '+'''%'+query_edarea.Text+'%''';
and_flag:=and_flag+1;
end;
end;
case f_query.ComboBox8.ItemIndex of
1: begin
if and_flag>0 then sql_select:=sql_select+' and';
sql_select:=sql_select+' Country like '+'''%'+query_edcountry.Text+'%''';
and_flag:=and_flag+1;
end;
2: begin
if and_flag>0 then sql_select:=sql_select+' or';
sql_select:=sql_select+' Country like '+'''%'+query_edcountry.Text+'%''';
and_flag:=and_flag+1;
end;
end;
case f_query.ComboBox9.ItemIndex of
1: begin
if and_flag>0 then sql_select:=sql_select+' and';
sql_select:=sql_select+' Ad_type like '+'''%'+query_edadtype.Text+'%''';
and_flag:=and_flag+1;
end;
2: begin
if and_flag>0 then sql_select:=sql_select+' or';
sql_select:=sql_select+' Ad_type like '+'''%'+query_edadtype.Text+'%''';
and_flag:=and_flag+1;
end;
end;
end;//判断是否有条件被选中*结束
//showmessage(sql_select);
dm.Query1.close;
dm.Query1.sql.Clear;
dm.Query1.sql.Add(sql_select);
if f_query.ComboBox10.ItemIndex=1 then
begin
DatetimeToString(date1,'yyyy-mm-dd',query_dtpfirst1.Date);
DatetimeToString(date2,'yyyy-mm-dd',query_dtpfirst2.Date);
dm.Query1.Filtered:=true;
dm.Query1.Filter:='first_recording>'+date1+'and first_recording<'+date2;
end;
if f_query.ComboBox11.ItemIndex=1 then
begin
DatetimeToString(date1,'yyyy-mm-dd',query_dtplast1.Date);
DatetimeToString(date2,'yyyy-mm-dd',query_dtplast2.Date);
dm.Query1.Filtered:=true;
dm.Query1.Filter:='last_recording>'+date1+'and last_recording<'+date2;
end;
dm.Query1.open;
if not dm.Query1.Eof and dm.Query1.Active then
begin
dm.Query1.Last;
dm.Query1.First;
f_result.lb_total.Caption:='共'+inttostr(dm.Query1.RecordCount)+'条';
end;
f_result.show;
f_query.Close;
end;