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
时间: 2024-12-17 11:22:08