取第m条到n条记录带查询条件问题

yyusnO 2008-12-10 09:57:00
asp+access

以下是代码段

<%'上面是查询
allcount=rsl.recordcount
IF allcount mod 20 <>0 THEN
S=INT(ALL/20+1)
ELSE
S=ALL/20
END IF%>
<%
m=1
n=20
FOR i=1 TO S%>
<div id=page<%=i%>>
<table>
<tr><td>表头</td></tr>
<%Set rs = Server.CreateObject ("ADODB.Recordset")
if n=20 then
sqll="select top "&ss&" * from [u_mains] where"
else
sqll="select top "&ss&" * from [u_mains] where id not in (select top "&sss&" id from u_mains order by id asc) and"
end if

if s_pc="1" then sqll=sqll&" u_pc='"&i_pc&"' and"
if s_rq="1" then sqll=sqll&" u_date between #"&InTime1&"# and #"&InTime2&"# and"
if s_cx="1" then sqll=sqll&" u_cx='"&i_cx&"' and"
if s_name="1" then sqll=sqll&" u_name='"&i_name&"' and"
if s_sex="1" then sqll=sqll&" u_sex='"&i_sex&"' and"
if s_card="1" then sqll=sqll&" u_card='"&i_card&"' and"
if s_tel="1" then sqll=sqll&" u_tel='"&i_tel&"' and"
if s_address="1" then sqll=sqll&" u_address like '%"&i_address&"%' and"
if right(sqll,5)="where" then sqll=left(sqll,clng(len(sqll))-5) ''''解决所有参数都为空的情况
if right(sqll,3)="and" then sqll=left(sqll,clng(len(sqll))-3) ''''去掉参数最后的and
sqll=sqll&" order by id asc"
response.Write(""&sqll&"")
rs.Open sqll,conn,1,1
if rs.EOF and rs.BOF then
Response.Write "暂时还没有内容"
else
page_count=m
do while not rs.eof%>
<tr><td>显示内容</td></tr>
<%page_count=page_count+1
rs.MoveNext
Loop
end if%>
</table>
</div>
<%N=N+20
M=M+20%>
<%NEXT%>


这段如果加上条件查询的话,就不输出,请高手帮忙哦
...全文
54 点赞 收藏 14
写回复
14 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
layers2323 2008-12-10
sqll="select top "&ss&" * from [u_mains] where id not in (select top "&sss&" id from u_mains where 条件字符串 order by id asc) and 条件字符串"
回复
zjsfdxbao 2008-12-10
if s_pc="1" then sqll=sqll&" u_pc='"&i_pc&"' and"
if s_rq="1" then sqll=sqll&" u_date between #"&InTime1&"# and #"&InTime2&"# and"
if s_cx="1" then sqll=sqll&" u_cx='"&i_cx&"' and"
if s_name="1" then sqll=sqll&" u_name='"&i_name&"' and"
if s_sex="1" then sqll=sqll&" u_sex='"&i_sex&"' and"
if s_card="1" then sqll=sqll&" u_card='"&i_card&"' and"
if s_tel="1" then sqll=sqll&" u_tel='"&i_tel&"' and"
if s_address="1" then sqll=sqll&" u_address like '%"&i_address&"%' and"
if right(sqll,5)="where" then sqll=left(sqll,clng(len(sqll))-5) ''''解决所有参数都为空的情况
if right(sqll,3)="and" then sqll=left(sqll,clng(len(sqll))-3) ''''去掉参数最后的and
这一堆附加条件应该也要加到内联表里面
回复
yyusnO 2008-12-10
明白了,我自己改改
回复
zjsfdxbao 2008-12-10
分页的语句没问题
回复
yyusnO 2008-12-10
哦,那我红色的语句应该怎么写哦~~luxu001207
回复
Atai-Lu 2008-12-10
sqll="select top "&ss&" * from [u_mains] where id not in (select top "&sss&" id from u_mains order by id asc) and"
红色这句的条件跟主句的条件要一样,排序也一样
回复
yyusnO 2008-12-10
wangkk125
这样试验了,不好用,取得是没有条件的数据
回复
wangkk125 2008-12-10
sqll="select top "&ss&" * from [u_mains] where id not in (select top "&sss&" id from u_mains order by id asc) and"+条件字符
改成这样
sqll="select top "&ss&" * from [u_mains] where id not in (select top "&sss&" id from u_mains where 条件字符 order by id asc)
回复
yyusnO 2008-12-10
错误倒是没有,就是
21select top 20 * from [u_mains] where id not in (select top 20 id from u_mains order by id asc) and u_pc='2' order by id asc
这是第2个层里显示的
显示的和第一个层的数据是一样的
如果不加条件的话,就都能显示出来,不包下面的条件
if s_pc="1" then sqll=sqll&" u_pc='"&i_pc&"' and"
if s_rq="1" then sqll=sqll&" u_date between #"&InTime1&"# and #"&InTime2&"# and"
if s_cx="1" then sqll=sqll&" u_cx='"&i_cx&"' and"
if s_name="1" then sqll=sqll&" u_name='"&i_name&"' and"
if s_sex="1" then sqll=sqll&" u_sex='"&i_sex&"' and"
if s_card="1" then sqll=sqll&" u_card='"&i_card&"' and"
if s_tel="1" then sqll=sqll&" u_tel='"&i_tel&"' and"
if s_address="1" then sqll=sqll&" u_address like '%"&i_address&"%' and"
回复
yyusnO 2008-12-10
不是分页,是分层显示,要做打印的哦,层的id不同
回复
zjsfdxbao 2008-12-10
不如你把错误的SQL抛出来大家看下更清晰,肯定是SQL字符串的问题
回复
文盲老顾 2008-12-10
是要实现分页?
回复
yyusnO 2008-12-10
这段打错了,all应该是allcount

<%'上面是查询
allcount=rsl.recordcount
IF allcount mod 20 <>0 THEN
S=INT(ALL/20+1)
ELSE
S=ALL/20
END IF%>
回复
yyusnO 2008-12-10
这段打错了,all应该是allcount

<%'上面是查询
allcount=rsl.recordcount
IF allcount mod 20 <>0 THEN
S=INT(ALL/20+1)
ELSE
S=ALL/20
END IF%>
回复
相关推荐
发帖
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
帖子事件
创建了帖子
2008-12-10 09:57
社区公告
暂无公告