SqlServer2005中利用存储过程分页
2010-12-08 21:29
399 查看
利用存储过程分页的Sql脚本如下,实际使用中利用存储过程部分就可以了。包括一个获取总记录数,以及查询结果集这两部分。
--进行top查询时 ,参数需要带上()
declare @page int,@pagesize int
set @page=2
select top (@page) * from usertb
--分页
select top 2 * from usertb where userid not in
(select top 2 userid from usertb order by username) order by username
--分页语句块
declare @pageSize int--页数大小
declare @pageIndex int--页码
set @pageSize = 2
set @pageIndex =1
select top ( @pagesize ) * from usertb
where userid not in(
select top (@pageSize*(@pageIndex-1)) userid
from usertb order by username )
order by username
--获得表的总数据量
create proc proc_countres(@count int output)
as
begin
select @count=count(*) from usertb
end
--根据用户指定的页码获得数据集
create proc proc_getres(@pageSize int,@pageIndex int)
as
begin
select top ( @pagesize ) * from usertb
where userid not in(
select top (@pageSize*(@pageIndex-1)) userid
from usertb order by username )
order by username
end
--获取指定页的结果集
exec proc_getres @pageSize=2,@pageIndex=1
--获得总的数据量
declare @count int
exec proc_countres @count output
print @count
--进行top查询时 ,参数需要带上()
declare @page int,@pagesize int
set @page=2
select top (@page) * from usertb
--分页
select top 2 * from usertb where userid not in
(select top 2 userid from usertb order by username) order by username
--分页语句块
declare @pageSize int--页数大小
declare @pageIndex int--页码
set @pageSize = 2
set @pageIndex =1
select top ( @pagesize ) * from usertb
where userid not in(
select top (@pageSize*(@pageIndex-1)) userid
from usertb order by username )
order by username
--获得表的总数据量
create proc proc_countres(@count int output)
as
begin
select @count=count(*) from usertb
end
--根据用户指定的页码获得数据集
create proc proc_getres(@pageSize int,@pageIndex int)
as
begin
select top ( @pagesize ) * from usertb
where userid not in(
select top (@pageSize*(@pageIndex-1)) userid
from usertb order by username )
order by username
end
--获取指定页的结果集
exec proc_getres @pageSize=2,@pageIndex=1
--获得总的数据量
declare @count int
exec proc_countres @count output
print @count
相关文章推荐
- sqlserver2005利用临时表和@@RowCount提高分页查询存储过程性能示例分享
- 利用SqlServer2005的新增函数实现更高效的分页存储过程
- SQL Server中利用存储过程来高性能地进行分页
- SQL Server中利用存储过程来高性能地进行分页
- 利用存储过程实现数据分页
- 利用存储过程分页
- ASP.NET中利用DataGrid的自定义分页功能和存储过程结合实现高效分页
- asp.net利用存储过程分页代码
- 利用SQL未公开的存储过程实现分页
- asp.net利用存储过程分页代码
- ASP.NET中利用DataGrid的自定义分页功能和存储过程结合实现高效分页
- ASP.NET中利用DataGrid的自定义分页功能和存储过程结合实现高效分页
- 修改后的SQL分页存储过程,利用2分法,支持排序
- ASP.NET中利用DataGrid的自定义分页功能和存储过程结合实现高效分页
- 在SQLServer2005下的通用分页存储过程
- 修改后的SQL分页存储过程,利用2分法,支持排序
- SQL Server中利用存储过程来高性能地进行分页
- asp.net利用存储过程分页代码
- 利用SQL的游标存储过程分页
- asp.net利用存储过程和div+css实现分页(类似于博客园首页分页)