SqlServer 分页存储过程

摘要:createproc[dbo].[proc_Opinion_BaseInfo]@TableNamevarchar(4000),@PkFieldvarchar(100),@PageIndexint=1,@PageSizeint=10,@sqlWherenvarchar(4000),@RowCountbigintoutpu

摘要:createproc[dbo].[proc_Opinion_BaseInfo]@TableNamevarchar(4000),@PkFieldvarchar(100),@PageIndexint=1,@PageSizeint=10,@sqlWherenvarchar(4000),@RowCountbigintoutpu。

SqlServer 分页存储过程


create proc [dbo].[proc_Opinion_BaseInfo] @TableName varchar(4000),@PkField varchar(100),@PageIndex int=1,@PageSize int=10,@sqlWhere nvarchar(4000),@RowCount bigint output,@PageCount bigint output as if(@sqlWhere=1) set @sqlWhere = 1=1 declare @sql nvarchar(4000),@start int,@end int set @sql=select * from (select Row_NUMBER() OVER(order by @PkField desc) rowId,* from @TableName where @sqlWhere set @start = (@PageIndex-1)*@PageSize 1 set @end = @start @PageSize-1 set @sql = @sql ) t where rowId between CAST(@start as varchar(20)) and CAST(@end as varchar(20)) exec (@sql) set @sql = select @RowCount=count(1) from @TableName where @sqlWhere exec sp_executesql @sql,N@RowCount bigint OUTPUT,@RowCount OUTPUT if(@RowCount%@PageSize=0) begin set @PageCount = @RowCount / @PageSize end else begin set @PageCount = @RowCount / @PageSize 1 end


总结

以上是为你收集整理的SqlServer 分页存储过程全部内容,希望文章能够帮你解决SqlServer 分页存储过程所遇到的程序开发问题。

0 条回复 A 作者 M 管理员
    所有的伟大,都源于一个勇敢的开始!
欢迎您,新朋友,感谢参与互动!欢迎您 {{author}},您在本站有{{commentsCount}}条评论