如何写分页存储过程

发布网友

我来回答

1个回答

热心网友

create proc 电影存储过程 --翻页存储过程
@PageSize int, --每页面显示数据条数
@PageIndex int, --页面索引
@PageCount int output, --总页数
@名称 nvarchar(100)
as
--查询范围 (@PageSize*@PageIndex+1) 起始行
-- @PageSize*(@PageIndex+1) 结束行

select * from(select Row_Number() over (order by 影片ID) as id, * from(
select * from 电影 where 名称 like '%'+@名称+'%' or 主演 like '%'+@名称+'%' )a )b where id between (@PageSize*@PageIndex+1) and @PageSize*(@PageIndex+1)

--得到数据行数
select @PageCount=count(1) from 电影 where 名称 like '%'+@名称+'%' or 主演 like '%'+@名称+'%'
--计算出总行数
set @PageCount= (@PageCount-1)/@PageSize+1
print @PageCount

这个是我写过的分页存储过程 给你参考下啊!

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com