首页 > 数据库 > Access > 正文

DataGrid连接Access的快速分页法(3)——SQL语句的选用(降序)

2024-09-07 19:04:58
字体:
来源:转载
供稿:网友
datagrid连接access的快速分页法(3)——sql语句的选用(降序)
三、降序
(1)@pageindex <= @firstindex
select top @pagesize @queryfields
from @tablename
where @condition
order by @primarykey desc


(2)@firstindex < @pageindex <= @middleindex

select top @pagesize @queryfields
from @tablename
where @primarykey < (
select min(@primarykey) from (
select top @pagesize*@pageindex @primarykey
from @tablename
where @condition
order by @primarykey desc
) tablea
) where @condition
order by @primarykey desc



(3)@middleindex < @pageindex < @lastindex

select * from (
select top @pagesize @queryfields
from @tablename
where @primarykey > (
select max(@primarykey) from (
select top (@[email protected]*(@pageindex+1)) @primarykey
from @tablename
where @condition
-- order by @primarykey asc
) tablea
) where @condition
-- order by @primarykey asc
) tableb
order by @primarykey desc



(4)@pageindex >= @lastindex

select * from (
select top (@[email protected]*@lastindex) @queryfields
from @tablename
where @condition
order by @primarykey asc
) tablea
order by @primarykey desc

四、总结
通过上面的讨论,相信大家应该看到了该分页方法的优势所在。在下一篇中,我将给大家一个动态生成上面 sql 语句的类。


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表