存储过程分页

create proc Proc_Page
(
@where nvarchar(max),
@pindex int,
@psize int,
@allcount int output,
@pagecount int output
)
as
begin
declare @totalsql nvarchar(max)
set @totalsql=‘select @allcount=count(1) from Student where 1=1 ‘+@where+’’
exec sp_executesql @totalsql,N’@allcount int output’,@allcount output
set @pagecount=ceiling(@allcount1.0/@psize)
declare @sql nvarchar(max),@start int,@end int
set @start=(@pindex-1)
@psize+1
set @end=@pindex*@psize
set @sql=‘select * from(select row_number() over(order by SId)tt,* from Student where 1=1 ‘+@where+’)t where t.tt between ‘+cast(@start as nvarchar(50))+’ and ‘+cast(@end as nvarchar(50))+’’
exec(@sql)

end
go
declare @all int,@pagecount int
exec Proc_Page ‘and SName=’‘张三’’’,1,3,@all output,@pagecount output
select @all,@pagecount

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值