34,590
社区成员
发帖
与我相关
我的任务
分享
ALTER PROCEDURE [dbo].[procSortPage]
(
@sqlString varchar(4000), --查询数据的语句
@PageSize int= 10, --页尺寸
@PageIndex int= 1, --页码
@PageCount int=0 output --总页数
)
AS
declare @RowCount int --总记录数
declare @strSelRowCount varchar(4000) --用来查询总记录数
set @strSelRowCount='select @RowCount= count(*) from ( '+@sqlString+' ) t'
sp_executesql @strSelRowCount,N'@RowCount output',@RowCount output
set @PageCount=@RowCount/@PageSize+1
go
declare @pagecount int;
exec procSortPage 'select * from test',2,2,@pagecount output
select @pagecount