sqlStr := ''; if checkBox1.Checked then sqlStr := sqlStr + ' and Age between 10 and 20'; if checkBox2.Checked then sqlStr := sqlStr + ' and Sex = ' + QuotedStr('男'); if... if...if sqlStr = '' then ADOQuery1.SQL.Text := 'select * from Table1'; else begin n := Pos('and', sqlStr); ADOQuery1.SQL.Text := 'select from Table1 where ' + Copy(sqlStr, n+3,200); end;
with ADOQuery1 do begin close; sql.clear; sql.add('select * from YourTableName where ID is not null '); if CheckBox1.Checked then sql.add('and .....'); if CheckBox2.Checked then sql.add('and .....'); .... open; end;
if checkBox1.Checked then
sqlStr := sqlStr + ' and Age between 10 and 20';
if checkBox2.Checked then
sqlStr := sqlStr + ' and Sex = ' + QuotedStr('男');
if...
if...if sqlStr = '' then
ADOQuery1.SQL.Text := 'select * from Table1';
else begin
n := Pos('and', sqlStr);
ADOQuery1.SQL.Text := 'select from Table1 where ' + Copy(sqlStr, n+3,200);
end;
with ADOQuery1 do
begin
close;
sql.clear;
sql.add('select * from YourTableName where ID is not null ');
if CheckBox1.Checked then
sql.add('and .....');
if CheckBox2.Checked then
sql.add('and .....');
....
open;
end;