05的分页存储过程改成2000的,我老改不对,希望指点

新亿 新亿 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区


CREATE proc [dbo].[UP_GetRecordByPage]
@tblName varchar(255), -- 表名
@fldName varchar(255), -- 排序字段(支持多字段,建议建索引) 比如 id asc ,addtime desc
@PageSize int = 10, -- 页尺寸
@PageIndex int = 1, -- 页码
--@IsReCount bit = 0, -- 返回记录总数, 非 0 值则返回
@TotalPages int output ,--输出参数,返回总页数
--@OrderType bit = 0, -- 设置排序类型, 非 0 值则降序
@strWhere varchar(1000) = '', -- 查询条件 (注意: 不要加 where)
@DataCount int output
AS
BEGIN
declare @strSql nvarchar(4000)
declare @rowsCount int
if Ltrim(Rtrim(@strWhere))=''
SET @strWhere=' 1=1 '
--obtain RowsCount
SET @strSql='select @TotalRecords=COUNT(*) from '+@tblName+' where '+@strWhere
execute SP_executesql @strSql,N'@TotalRecords int output ',@rowsCount output
select @DataCount=@rowsCount
select @TotalPages=CEILING((@rowsCount+0.0)/@PageSize)
if @PageIndex<=0
SET @PageIndex=1
if @PageIndex > @TotalPages
SET @PageIndex=@TotalPages
SET @strSql='select * from (select top (@PageIndex*@PageSize) * ,ROW_NUMBER() OVER(order by '+@fldName+') as rowNumber from '+@tblName+' where '+@strWhere+' ) t where t.rowNumber>=((@PageIndex-1)*@PageSize+1)'
print @strSql
exec sp_executesql @strSql,N'@PageIndex int, @PageSize int',@PageIndex,@PageSize
END



GO




保持传入和传出参数不变啊,因为我不想去改程序代码了, 执行存储过程的就这样,解决的给满分
...全文

相关推荐

评论 19
收藏 已收藏
分享
返回顶部
新亿
疑难问题 22,298 成员 121,727 内容