3 回答
TA贡献1825条经验 获得超6个赞
asp多条件符合查询,参考代码如下:
<%
dim qy
qy=0
if request.form("stu_name")<>"" then '第一个条件表单传递的数据
str="stu_name='"&request.form("stu_name")&"'"
qy=qy+1
end if
if request.form("stu_num")<>"" then '第二个条件表单传递的数据
if qy=0 then
str=str&"stu_number='"&request.form("stu_num")&"'"
else
str=str&"and stu_number='"&request.form("stu_num")&"'"
end if
qy=qy+1
end if
if request.form("stu_xibie")<>"" then '第三个条件表单传递的数据
if qy=0 then
str=str&"stu_xibie='"&request.form("stu_xibie")&"'"
else
str=str&"and stu_xibie='"&request.form("stu_xibie")&"'"
end if
qy=qy+1
end if
if request.form("stu_class")<>"" then
if qy=0 then
str=str&"stu_class='"&request.form("stu_class")&"'"
else
str=str&"and stu_class='"&request.form("stu_class")&"'"
end if
qy=qy+1
end if
if request.form("stu_year")<>"" then
if qy=0 then
str=str&"stu_year='"&request.form("stu_year")&"'"
else
str=str&"and stu_year='"&request.form("stu_year")&"'"
end if
qy=qy+1
end if
sql="select * from [students] where "&str
Set rs=Conn.Execute(sql) '执行sql语句
%>
TA贡献1848条经验 获得超6个赞
TA贡献1864条经验 获得超2个赞
<%
if request.querystring("act")="cha" Then
caizhi=request("caizhi")
guige=request("guige")
chandi=request("chandi")
huoyuan=request("huoyuan")
if caizhi="" and guige="" and chandi="" and huoyuan="" then
exec="select * from juanban where 1=1"
else
exec="select * from juanban where 材质 like '"&caizhi&"' or 规格 like '"&guige&"' or 产地 like '"&chandi&"' or 货源 like '"&huoyuan&"'"
end if
end if
set rs2=server.createobject("adodb.recordset")
rs2.open exec,conn,1,1
do while not rs2.eof %>
添加回答
举报