如:
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
<%<!--#include file="../com.asp"-->
<!--#include file="../info.asp"-->
if request("n")<>"" then
sl=request("sname")
set rs = server.CreateObject("adodb.recordset")
dim tl
if sl="" then
response.Write("注意!你的变量sl是空值 sql语句会报错!")
response.End()
end if
tl=request(trim("tl"))
select case tl
case "daima"
sql="select * from H_yesterday where daima='"&sl&"'"
case "gpm"
sql="select * from H_yesterday where gpm='"&sl&"'"
case "times"
sql="select * from H_yesterday where tims='"&sl&"'"
case else
sql="select * from H_yesterday where tims='"&sl&"'"
end select
rs.PageSize = 26 '这里设定每页显示的记录数
rs.CursorLocation = 3
rs.Open sql,conn,1,1'这120行
%>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)