经过多次研究写出了如下代码,有需要的可以参考下
复制代码 代码如下:
kd=server.HTMLEncode(request("keyword"))
if kd<>"" then
kd=trim(kd)
'kd=replace(kd," ","")
kd=replace(kd,"'","")
kd=replace(kd,"%","")
kd=replace(kd,"\"," ")
kd=replace(kd,">",">")
kd=replace(kd,"<","<")
kd=replace(kd,","," ")
kd=replace(kd,","," ")
kd=replace(kd,"|"," ")
kd=replace(kd,";"," ")
kd=replace(kd,":"," ")
kd=replace(kd,":"," ")
kd=replace(kd,";"," ")
'上面的是先替换一些特殊字符,方便输入一些特殊的分隔符
keyarr= Split(kd," ")
keyarrl=ubound(keyarr)
For I = 0 to keyarrl
if keyarrl>0 then
sqlk=sqlk&" and title like '%"&keyarr(I)&"%'"
else
sqlk=sqlk&"and title like '%"&keyarr(I)&"%'"
end if
Next
if id<>"" then
sql="select top 1000 id,title from news where type_id in ("&sqqq&") "&sqlk&" order by isshow ,shengcheng,id desc"
else
sql="select top 1000 id,title from news where id<>0 "&sqlk&" order by isshow ,shengcheng,id desc"
end if
else
if id<>"" then
sql="select top 1000 id,title from news where type_id in ("&sqqq&") order by isshow ,shengcheng,id desc"
else
sql="select top 1000 id,title from news where id<>0 order by isshow ,shengcheng,id desc"
end if
end if
ASP 多条件符合查询代码实例2
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
内容版权声明:除非注明,否则皆为本站原创文章。