请高手帮看下存储分页

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

CREATE procedure Sj_GetData
@TableList Varchar(200)='*',--搜索表的字段
@TableName Varchar(30), --搜索的表名
@TableName1 Varchar(30), --搜索的表名
@SelectWhere Varchar(500)='',--搜索条件
@SelectOrderId Varchar(20),--表主键字段名。
@SelectOrder Varchar(200)='', --排序
@intPageNo int=1, --页号
@intPageSize int=10 ,--每页显示数
@RecordCount int OUTPUT --总记录数(存储过程输出参数)
as

declare @TmpSelect NVarchar(600)
declare @Tmp NVarchar(600)

set nocount on--关闭计数

set @TmpSelect = 'select @RecordCount = count(*) from '+@TableName+' '+@SelectWhere

execute sp_executesql
@TmpSelect, --执行上面的sql语句
N'@RecordCount int OUTPUT' , --执行输出数据的sql语句,output出总记录数
@RecordCount OUTPUT

if (@RecordCount = 0) --如果没有贴子,则返回零
return 0

/*判断页数是否正确*/
if (@intPageNo - 1) * @intPageSize > @RecordCount --页号大于总页数,返回错误
return (-1)
set nocount off--打开计数
if @SelectWhere != ' '
begin
set @TmpSelect = 'select top '+str(@intPageSize)+' '+@TableList+' from '+@TableName+' inner join '+@TableName1+' on '+@TableName+'.ZiLeiID='+@TableName1+'.ID '+@SelectWhere +' and '+@SelectOrderId+' not in(select top '+str

(@intPageNo*@intPageSize-@intPageSize)+' '+@SelectOrderId+' from '+@TableName+' inner join '+@TableName1+' on '+@TableName+'.ZiLeiID='+@TableName1+'.ID '+@SelectOrder+') '+@SelectOrder
end
else
begin
set @TmpSelect = 'select top '+str(@intPageSize)+' '+@TableList+' from '+@TableName+' inner join '+@TableName1+' on '+@TableName+'.ZiLeiID='+@TableName1+'.ID where '+@SelectOrderId+' not in
(select top '+str((@intPageNo-1)*@intPageSize)+' '+@SelectOrderId+' from '+@TableName+' inner join '+@TableName1+' on '+@TableName+'.ZiLeiID='+@TableName1+'.ID '+@SelectOrder+') '+@SelectOrder
end
execute sp_executesql @TmpSelect
return(@@rowcount)
GO

比如说
我设置
@intPageNo int=1, --页号
@intPageSize int=10 ,--每页显示数
当换成下一页时
只更新了一条记录
其他9条还是前一页的
请指教下呀
改了以下午也没效果郁闷饿
...全文

相关推荐

评论 6
收藏 已收藏
分享
返回顶部
sijin
应用实例 27,579 成员 68,540 内容