分页 存储过程
2007-02-09 00:04
162 查看
方法一(任何条件的SQL语句'):
create procedure XiaoZhengGe
@sqlstr nvarchar(4000), --查询字符串
@currentpage int,--第N页
@pagesize int--每页行数
as
set nocount on
declare @P1 int,--P1是游标的id
@rowcount int
exec sp_cursoropen @P1 output,@sqlstr,@scrollopt=1,@ccopt=1,@rowcount=@rowcount output
select ceiling(1.0*@rowcount/@pagesize) as 总页数--,@rowcount as 总行数,@currentpage as 当前页
set @currentpage=(@currentpage-1)*@pagesize+1
exec sp_cursorfetch @P1,16,@currentpage,@pagesize
exec sp_cursorclose @P1
set nocount off
测试: XiaoZhengGe '任何条件的SQL语句',2,10
方法二(前面的页面记取快,越往后读越慢):
lihonggen0(李洪根,MS MVP)
假若你用几十万行数据,你可以看看.
你的存储过程还比不上NOT IN分页,示例:
SELECT Top 10 * FROM Customers WHERE Customerid NOT IN (SELECT TOP 20 Customerid from Customers )
declare @SQLStr varchar(8000)
set @SQLStr='SELECT Top '+cast(@每页大小 as varchar)+' * FROM 表 WHERE 主键列 NOT IN (SELECT TOP '+cast(@每页大小*@第几页 as varchar)+' 主键列 from 表 )'
exec(@SQLStr)
我个人认为最好的分页方法是:
Select top 10 * from table where id>200
写成存储过程,上面的语句要拼一下sql语句,要获得最后大于的哪一个ID号
create procedure XiaoZhengGe
@sqlstr nvarchar(4000), --查询字符串
@currentpage int,--第N页
@pagesize int--每页行数
as
set nocount on
declare @P1 int,--P1是游标的id
@rowcount int
exec sp_cursoropen @P1 output,@sqlstr,@scrollopt=1,@ccopt=1,@rowcount=@rowcount output
select ceiling(1.0*@rowcount/@pagesize) as 总页数--,@rowcount as 总行数,@currentpage as 当前页
set @currentpage=(@currentpage-1)*@pagesize+1
exec sp_cursorfetch @P1,16,@currentpage,@pagesize
exec sp_cursorclose @P1
set nocount off
测试: XiaoZhengGe '任何条件的SQL语句',2,10
方法二(前面的页面记取快,越往后读越慢):
lihonggen0(李洪根,MS MVP)
假若你用几十万行数据,你可以看看.
你的存储过程还比不上NOT IN分页,示例:
SELECT Top 10 * FROM Customers WHERE Customerid NOT IN (SELECT TOP 20 Customerid from Customers )
declare @SQLStr varchar(8000)
set @SQLStr='SELECT Top '+cast(@每页大小 as varchar)+' * FROM 表 WHERE 主键列 NOT IN (SELECT TOP '+cast(@每页大小*@第几页 as varchar)+' 主键列 from 表 )'
exec(@SQLStr)
我个人认为最好的分页方法是:
Select top 10 * from table where id>200
写成存储过程,上面的语句要拼一下sql语句,要获得最后大于的哪一个ID号
相关文章推荐
- [转]SQL Server 存储过程的分页方案比拼
- oracle 分页存储过程,带有排序
- mvc,EntityFramework调用分页存储过程
- 最通用的分页存储过程
- 千万级通用的分页存储过程
- 常用的分页存储过程
- 分页存储过程:自己写的
- Delphi调用SQL分页存储过程实例
- 不用存储实现的分页,效率和存储过程一样。
- 多表查询分页存储过程,解决了第二页不显示的问题
- 不错的sql分页存储过程
- ASPNET与存储过程进行分页示例
- 存储过程的分页(对比)
- 简单搞一下 Oracle 存储过程动态SQL之获取查询分页!
- sql 学习之主键选择、简单分页存储过程
- 还是分页的存储过程!
- 存储过程DataGrid分页及注意点
- 分页存储过程:排序反转分页法
- SQL Server 存储过程的分页
- 千万数量级分页存储过程,可支持多表查询,任意排序