3 回答
TA贡献1821条经验 获得超6个赞
if request("neirong")<>"" and request("riqi1")=""then
sql="select * from renyuan where id="&request("id")&" and "&request("tiaojian")&"='"&request("neirong")&"'"
elseif request("neirong")="" and request("riqi1")<>"" and request("riqi2")<>"" then
sql="select * from renyuan where id="&request("id")&" and shengri between #"&request("riqi1")&"# and #"&request("riqi2")&"#"
elseif request("neirong")<>"" and request("riqi1")<>"" and request("riqi2")<>"" then
sql="select * from renyuan where id="&request("id")&" and "&request("tiaojian")&"='"&request("neirong")&"'and shengri between #"&request("riqi1")&"# and #"&request("riqi2")&"#"
end if
TA贡献1827条经验 获得超9个赞
这就是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
TA贡献1784条经验 获得超2个赞
思路:
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 <> "" Then
sql = sql & " and replace(studentname,' ','') like '%" & studentname & "%'"
End If
if Tel <> "" then
sql =sql &" and studentTel like '%"&Tel&"%'"
End If
rs.open session("sql"),ConnDb,1,1
If rs.eof And rs.bof Then
'提示信息
Else
'输出数据
End If
%>
不知道你目前做到什么程序了。
添加回答
举报