如何把asp多条件查询操作语句精简?

如何把asp多条件查询操作语句精简


江户川乱折腾
浏览 1418回答 3
3回答

达令说

if&nbsp;request("neirong")<>""&nbsp;and&nbsp;request("riqi1")=""thensql="select&nbsp;*&nbsp;from&nbsp;renyuan&nbsp;where&nbsp;id="&request("id")&"&nbsp;and&nbsp;"&request("tiaojian")&"='"&request("neirong")&"'"elseif&nbsp;request("neirong")=""&nbsp;and&nbsp;request("riqi1")<>""&nbsp;and&nbsp;request("riqi2")<>""&nbsp;thensql="select&nbsp;*&nbsp;from&nbsp;renyuan&nbsp;where&nbsp;id="&request("id")&"&nbsp;and&nbsp;shengri&nbsp;between&nbsp;#"&request("riqi1")&"#&nbsp;and&nbsp;#"&request("riqi2")&"#"elseif&nbsp;request("neirong")<>""&nbsp;and&nbsp;request("riqi1")<>""&nbsp;and&nbsp;request("riqi2")<>""&nbsp;thensql="select&nbsp;*&nbsp;from&nbsp;renyuan&nbsp;where&nbsp;id="&request("id")&"&nbsp;and&nbsp;"&request("tiaojian")&"='"&request("neirong")&"'and&nbsp;shengri&nbsp;between&nbsp;#"&request("riqi1")&"#&nbsp;and&nbsp;#"&request("riqi2")&"#"end&nbsp;if

素胚勾勒不出你

这就是SQL拼接的问题了!如:sql="1=1"if request("条件1")<>"" then sql=sql&" and 查询字段1='"&request("条件1")&"'"if request("条件2")<>"" then sql=sql&" and 查询字段2='"&request("条件2")&"'"if request("条件3")<>"" then sql=sql&" and 查询字段3='"&request("条件3")&"'"if request("条件4")<>"" then sql=sql&" and 查询字段4='"&request("条件4")&"'"if request("条件5")<>"" then sql=sql&" and 查询字段5='"&request("条件5")&"'"if request("条件6")<>"" then sql=sql&" and 查询字段6 like '%"&request("条件6")&"%'" '模糊查询if request("条件N")<>"" then sql=sql&" and 查询字段N='"&request("条件N")&"'"这样的就把SQL的条件语句给拼接了,然后再看以下:set rs=server.createobject("adodb.recordset")sql="select * from 表名 where "&sql&""rs.open sql,conn,1,1

一只斗牛犬

思路:1、表单页面,设置多个查询的文本框<form name="search" method="post" action="searchresult.asp">学生名字:<input type="text" name="studentname" />联系方式:<input type="text" name="Tel" /><input type="submit" name="submit" value="提交查询" class="formsubmit" /></form>2、表单处理页面,根据查询文本框的内容,组合成SQL语句,到数据库中查询<%studentname = trim(request.Form("studentname"))Tel = trim(request.Form("Tel"))sql = "select * from [tablename] where ()"If studentname <> "" Thensql = sql & " and replace(studentname,' ','') like '%" & studentname & "%'"End Ifif Tel <> "" thensql =sql &" and studentTel like '%"&Tel&"%'"End Ifrs.open session("sql"),ConnDb,1,1If rs.eof And rs.bof Then'提示信息Else'输出数据End If%>不知道你目前做到什么程序了。
打开App,查看更多内容
随时随地看视频慕课网APP