两个表的分页存储过程

create proc [dbo].[usp_contacts_select_by_page]--存储过程名称

@pageindex int,--当前页

@pagesize int,--每页条数

@pagecount int output,--总页数

@recordcount int output--总条数

as

begin

select c1.*,c2.groupName into #tmp_contacts from Contacts as c1 inner join

ContactGroup as c2 on c1.groupId=c2.groupId--将两个表中的数据存放到临时表中

select * from

(select *,rn=ROW_NUMBER()over(order by contactId asc)from #tmp_contacts)as t

where t.rn between(@pageindex-1)*@pagesize+1 and @pageindex*@pagesize

set @recordcount=(select COUNT(*)from #tmp_contacts)

set @pagecount=CEILING(@recordcount*1.0/@pagesize)

end

执行

declare @m int,@n int

exec [dbo].[usp_contacts_select_by_page] 2,5,@m output,@n output

print @m

print @n

转载于:https://www.cnblogs.com/zhuyuchao/p/5634188.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值