| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 516 人关注过本帖
标题:各位大哥,帮小弟看看下面存储过程分页代码有什么错误.
取消只看楼主 加入收藏
guduhuan520
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2012-7-17
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
各位大哥,帮小弟看看下面存储过程分页代码有什么错误.
小弟不胜感激!
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go


ALTER proc [sq_bluewarship].[getdat]
@TableList Varchar(200)='*',--搜索表的字段,比如:’id,datatime,job‘,用逗号隔开
@TableName Varchar(30), --搜索的表名
@SelectWhere Varchar(500)='',--搜索条件,这里不用写where,
@SelectOrderId Varchar(30),--表主键字段名。比如:id
@SelectOrder Varchar(200)='', --排序,可以使用多字段排序但主键字段必需在最前面.也可以不写,比如:order by class asc
@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+' where '+@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+' where '+@SelectOrderId+' not in(select top '+str((@intPageNo-1)*@intPageSize)+' '+@SelectOrderId+' from '+@TableName+' where '+@SelectWhere +' '+@SelectOrder+') and '+@SelectWhere +''+@SelectOrder
end
else
begin
set @TmpSelect = 'select top '+str(@intPageSize)+' '+@TableList+' from '+@TableName+' where '+@SelectOrderId+' not in(select top '+str((@intPageNo-1)*@intPageSize)+' '+@SelectOrderId+' from '+@TableName+' '+@SelectOrder+') '+@SelectOrder
end
execute sp_executesql @TmpSelect
return(@@rowcount)
搜索更多相关主题的帖子: 搜索 不胜感激 where 
2012-07-17 17:41
guduhuan520
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2012-7-17
收藏
得分:0 
大家帮帮忙。
图片附件: 游客没有浏览图片的权限,请 登录注册
错误说where附近都错误。
2012-07-17 17:49
快速回复:各位大哥,帮小弟看看下面存储过程分页代码有什么错误.
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019388 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved