多种组合查询
有六个空(文本框), 可以组成多种条件进行查询,写查询代码时,太多了,写得手软,有没有一种简捷的方式,比如函数或者循环,只要知道有多少个条件,自动生成多种条件查询代码,
谢谢 !
Dim title,classid,html,ispic,istop cat=0 title=Trim(Replace(Request.Form("title"),"'","")) classid=Request.Form("classid") html=Trim(Replace(Request.Form("html"),"'","")) isspe=Request.Form("isspe") ispic=Request.Form("ispic") istop=Request.Form("istop") sql="select id,title,istop,ispic,isspe,ClassID,filepath,filename from News where " if title<>"" then sql=sql&" title like '%"&title&"%' " cat=1 end if if classid<>"" and cat=1 then sql=sql&" and classid = "&classid cat=1 elseif classid<>"" then sql=sql&" classid = "&classid cat=1 end if if html<>"" and cat=1 then sql=sql&" and filename = '"&html&"' " cat=1 elseif html<>"" then sql=sql&" filename = '"&html&"' " cat=1 end if if isspe<>"" and cat=1 then sql=sql&" and isspe = True " cat=1 elseif isspe<>"" then sql=sql&" isspe = True " cat=1 end if if ispic<>"" and cat=1 then sql=sql&" and ispic = True " cat=1 elseif ispic<>"" then sql=sql&" ispic = True " cat=1 end if if istop<>"" and cat=1 then sql=sql&" and istop = True " cat=1 elseif istop<>"" then sql=sql&" istop = True " cat=1 end if set rs=server.CreateObject("adodb.recordset") rs.open sql,conn,1,1