大约是这样:我有五个或更多的EDIT,如果五个都不为空的话就SELECT * FROM TABLE WHERE 条件1 LIKE EDIT1 AND 条件2 LIKE EDIT2......AND 条件5 LIKE EDIT5
如果只有EDIT2和EDIT3填了数据就SELECT * FROM TABLE WHERE 条件2 LIKE EDIT2 AND 条件3 LIKE EDIT3
意思是如果5个都不为空就有5个条件,只3个填EDIT的数据,就有3个条件,以此类推.
请问各位大侠,小弟应该如何判断和写代码呢?
小弟初学,请各位哥哥姐姐说详细点好吗?最好能有代码示范一下.谢谢了.
如果只有EDIT2和EDIT3填了数据就SELECT * FROM TABLE WHERE 条件2 LIKE EDIT2 AND 条件3 LIKE EDIT3
意思是如果5个都不为空就有5个条件,只3个填EDIT的数据,就有3个条件,以此类推.
请问各位大侠,小弟应该如何判断和写代码呢?
小弟初学,请各位哥哥姐姐说详细点好吗?最好能有代码示范一下.谢谢了.
a1,a2:string;
sqlt,sqltemp:string;
begin
a1:=trim(edit1.text);
a2:=trim(edit2.text);
with adoquery1 do
begin
sqlt:='select * form 表名';
if length(a1)>0 then
sqltemp:='字段名 like ''%'+a1+'%''';
if length(a2)>0 then
sqltemp:=sqltemp+'字段名 like ''%'+a2+'%''';
if length(sqltemp)>0 then
begin
if uppercase(copy(TrimLeft(sqltemp),1,2))<>'WHERE' then
sqltemp:=' where '+sqltemp;
if trim(uppercase(copy(TrimRight(sqltemp),length(TrimRight(sqltemp))-3,length(TrimRight(sqltemp)))))='AND' then
sqltemp:=copy(TrimRight(sqltemp),1,length(TrimRight(sqltemp))-3);
end;
Close;
SQL.Clear;
SQL.Add(sqlt+sqltemp);
Open;
end;
end;
str := '';
if combobox2.Text <> '' then str := 'yhbh=''' + combobox2.text + '''';
if combobox3.Text <> '' then
if str <> '' then
str := str + ' and sbbh=''' + combobox3.text + ''''
else
str := str + ' sbbh=''' + combobox3.text + '''';
if edit3.Text <> '' then
if str <> '' then
str := str + ' and nd=''' + edit3.text + ''''
else
str := str + ' nd=''' + edit3.Text + '''';
if combobox1.Text <> '' then
if str <> '' then
str := str + ' and yf=''' + combobox1.Text + ''''
else
str := str + ' yf=''' + combobox1.Text + '''';
if RadioButton1.Checked = true then
begin
if str <> '' then
str := str + ' and sfycb =1'
else
str := str + ' sfycb =1';
end;
if RadioButton2.Checked = true then
begin
if str <> '' then
str := str + ' and sfycb =0'
else
str := str + ' sfycb =0';
end;
adoquery2.Filter := str;
adoquery2.Filtered := true;