SQL语句where可以嵌套循环语句吗?????

goshyboy1 2009-03-31 08:13:01
<%
set searchrs=server.createobject("adodb.recordset")
searchsql="Select top 20 * from 2s_list where IsShow=true and sxs =0 "
if title<>"" then
Set RST=Server.CreateObject("ADODB.RecordSet")
StrSQL=AutoKey(title) ''此处使用自定义函数 AutoKey(),该函数为实现智能搜索的核心
RST.Open StrSQL,conn_fenxi,3,2 ''得到搜索后的记录
If RST.BOF And RST.EOF Then
else
While Not RST.EOF
searchsql=searchsql&" or title like '%"&RST("U_Name")&"%'“
RST.MoveNext
Wend
end if
end if
if Nclassid<>"" then searchsql=searchsql&" and Nclassid ="&Nclassid&""
if classid<>"" then searchsql=searchsql&" and classid ="&classid&""
if dq<>"" then searchsql=searchsql&" and dq LIKE '%"&dq&"%'"
if lx<>"" then searchsql=searchsql&" and lx ="&lx&""
if yx<>"" then
searchsql=searchsql&" and DateDiff('d',now(),jx)>0"
end if
searchsql=searchsql&" order by s_id desc"
searchrs.open searchsql,conn,1,1
if searchrs.eof and searchrs.bof then
else
%>

<%
Function AutoKey(strKey)
'361du.net
CONST lngSubKey=2
Dim lngLenKey, strNew1, strNew2, i, strSubKey
'检测字符串的合法性,若不合法则转到出错页。出错页你可以根据需要进行设定。
if InStr(strKey,"=")<>0 or InStr(strKey,"`")<>0 or InStr(strKey,chr(34))<>0 or InStr(strKey,"\")<>0 or InStr(strKey,",")<>0 or InStr(strKey,"<")<>0 or InStr(strKey,">")<>0 then
Response.Redirect "error.htm"
End If
lngLenKey=Len(strKey)
Select Case lngLenKey
Case 0 '若为空串,转到出错页
Response.Redirect "error.htm"
Case 1 '若长度为1,则不设任何值
strNew1=""
strNew2=""
Case Else '若长度大于1,则从字符串首字符开始,循环取长度为2的子字符串作为查询条件
For i=1 To lngLenKey-(lngSubKey-1)
strSubKey=Mid(strKey,i,lngSubKey)
strNew1=strNew1 & " or U_Name like '%"&strSubKey&"%'"
Next
End Select
'得到完整的SQL语句
AutoKey="Select * from cnword where U_Name like '%"&strKey&"%'" &strNew1& "order by id desc"
End Function
%>

两个数据库都是Access的 我这样做不成功 求高手帮我做一下 谢谢啊
...全文
618 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
金清 2012-06-10
  • 打赏
  • 举报
回复
不懂事什么问题,哎,爱莫能助啊
cr75608859 2011-08-22
  • 打赏
  • 举报
回复
一大串的 楼主问题不明确
armstrong1225 2009-04-01
  • 打赏
  • 举报
回复
再此学习了
ACMAIN_CHM 2009-04-01
  • 打赏
  • 举报
回复
[Quote=引用楼主 goshyboy1 的帖子:]
两个数据库都是Access的 我这样做不成功 求高手帮我做一下 谢谢啊[/Quote]

你所说的不成功是指什么问题?网页运行出错?还是数据显示结果不是预期的?

QQ群 48866293 / 12035577 / 7440532 / 13666209
ACCESS专业论坛
http://www.accessbbs.cn/bbs/index.php .
http://www.office-cn.net/vvb/ .
http://www.accessoft.com/bbs/index.asp .
http://www.access-programmers.co.uk/forums .
.
http://www.office-cn.net/home/space.php?uid=141646 .
receive099 2009-04-01
  • 打赏
  • 举报
回复
不懂,帮顶
wwwwb 2009-04-01
  • 打赏
  • 举报
回复
简单地讲,问题出在哪里

7,732

社区成员

发帖
与我相关
我的任务
社区描述
Microsoft Office Access是由微软发布的关系数据库管理系统。它结合了 MicrosoftJet Database Engine 和 图形用户界面两项特点。
社区管理员
  • Access
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧