如何完成可选多条件组合的查询!(100分)

H

hcbride

Unregistered / Unconfirmed
GUEST, unregistred user!
请问高手:用query如何做到,多条件的组合查询。这些条件可以是空的!
 
Sele_where := '';
//条件1
if Condition1 <> '' then
Begin
if Sele_Where <> '' then
Sele_Where := Sele_Where + ' and ';
Sele_where := sele_where + 'Field1 = Condition1';
end;
...
//条件X
if ConditionX <> '' then
Begin
if Sele_Where <> '' then
Sele_Where := Sele_Where + ' and ';
Sele_where := sele_where + 'FieldX = ConditionX';
end;
if Sele_Where <> '' then
Sele_SQL := 'select * from table1' + ' where ' + Sele_Where
else
Sele_SQL := 'select * from table1';

With Query1 do
Begin
Close;
SQL.Clear;
SQL.Add(Sele_SQL);
Open;
end;
 
接受答案了.
 
顶部