你参照我的看看:
strsql = "select * from table1 where 1 = 1 " if trim(request("n"))<>"" then
strsql = strsql &" and n like '%" &trim(request("n")) &"%'"
end if if trim(request("b"))<>"" then
strsql=strsql & " and b like '%" &trim(request("b")) & "%'"
end if if trim(request("lessor"))<>"" then
strsql=strsql & " and c like '%" &trim(request("c")) & "%'"
end if
strsql = "select * from table1 where 1 = 1 " if trim(request("n"))<>"" then
strsql = strsql &" and n like '%" &trim(request("n")) &"%'"
end if if trim(request("b"))<>"" then
strsql=strsql & " and b like '%" &trim(request("b")) & "%'"
end if if trim(request("lessor"))<>"" then
strsql=strsql & " and c like '%" &trim(request("c")) & "%'"
end if
String f1=request.getParameter("f1");
String f2=request.getParameter("f2");
String f3=request.getParameter("f3");
String sql="select * from tablename where 1=1 ";
if(!f1.trim().equals(""))
sql+=" or fieldname1='"+f1+"' ";
if(!f2.trim().equals(""))
sql+=" or fieldname2='"+f2+"' ";
if(!f3.trim().equals(""))
sql+=" or fieldname3='"+f3+"' ";
Result rs=stm.executeQuery(sql);
and
2 if()
and
...........