var
sarray:array[1..4]of string;
sboolean:boolean;
sstr:string;
i:integer;
begin
if c1.Checked=true then
sarray[1]:='日期>='+''''+formatdatetime('yyyy-mm-dd',d1.date)+''''+' and 日期<='+''''+formatdatetime('yyyy-mm-dd',d2.date)+''''
else sarray[1]:='';
if c2.Checked=true then sarray[2]:='车型='+''''+sncombobox1.Text+''''
else sarray[2]:='';
if c3.Checked=true then sarray[3]:='颜色='+''''+sncombobox2.Text+''''
else sarray[3]:='';
if c4.Checked=true then sarray[4]:='类别=''出口车'''
else sarray[4]:='';
sboolean:=true;
sstr:='';
for i:=1 to 4 do
begin
if sarray[i]<>'' then
begin
if sboolean=true then
begin
sstr:=sstr+sarray[i];
sboolean:=false;
end
else sstr:=sstr+' and '+sarray[i];
end;
end;
if sstr='' then exit
else sstr:=' where '+sstr;
adoquery1.Close;
adoquery1.SQL.Clear;
sstr:='select * from tablename'+sstr;
adoquery1.SQL.Add(sstr);
adoquery1.open;
其中c1,c2,c3,c4是checkbox
var
str:string;
begin
if edit1.Text<>'' then
str:='where 性别='+edit1.Text+''
else
str:='';
if edit2.Text<>'' then
begin
if edit1.Text='' then
str:= 'where kkk='+edit2.Text+''
else
str:=str+'and kkk='+edit2.Text+'' ;
end else
str:=str;
if edit3.Text<>'' then
begin
if (edit1.Text='') and (edit2.Text='') then
str:= 'where www='+edit3.Text+''
else
str:=str+'and www='+edit3.Text+'' ;
end else
str:=str ;
SQL语句、、、
if edit1.text<>'' then
sqlstr:=sqlstr+' and ...';
if checkbox1.checked then
sqlstr:=sqlstr+' and....';
if combobox1.itemindex>0 then
sqlstr:=sqlstr+' and....';