当前位置:Gxlcms > 数据库问题 > SQL基础分页存储过程(案例一)

SQL基础分页存储过程(案例一)

时间:2021-07-01 10:21:17 帮助过:20人阅读

--分页 存储过程 案例 2 3 -- 所执行的存储过程 4 create proc pageForUsers 5 @currPage int, --当前页数 6 @pageSize int, --每页多少条记录 7 @count int output --总记录数 8 as 9 declare @firstIndex int 10 declare @lastIndex int 11 declare @sqlText varchar(200) 12 13 --统计总记录数 14 select @count=count(*) from users 15 --首先计算当前页第一条记录索引 16 set @firstIndex=(@currPage - 1) * @pageSize + 1 17 --当前页最后一条记录索引 18 set @lastIndex = @firstIndex + @pageSize - 1 19 --显示结果 20 set @sqlText=select top + convert(varchar(5),@pageSize) + * from users 21 where [id] not in (select top + convert(varchar(5),@firstIndex-1) + [id] from users) 22 exec (@sqlText) 23

 

SQL基础分页存储过程(案例一)

标签:nbsp   set   rom   sql基础   过程   use   span   统计   code   

人气教程排行