if exists(select name from sysobjects where name = N'pageQuery')--加N表示为常量
drop proc pageQuery
gocreate proc pageQuery
@areaId varchar(10)='SH',@returnCol nvarchar(100)='*',--返回的列,默认值为*@pageSize int,--每页数据数量@colname nvarchar(20),--依据排序的列,实际上是根据行号排序@tableName nvarchar(50),--表名@pageIndex int,--页码@isDesc int=0,--是否降序@where nvarchar(200)='',--where条件子句@sum int output--记录总条数as
declare @parm nvarchar(100)--定义调用系统存储过程sp_executesql时需要用到的output参数set @parm=N'@s int output'--给output参数赋值declare @tempsql nvarchar(200)--定义临时sql语句set @tempsql=N'select @s=count(*) from '+@tableName +' where manageResult is null and AreaId=@areaId' --给临时sql语句declare @sumPage int--定义接收记录总条数的变量exec sp_executesql @tempsql,@parm,@s=@sum output--执行系统存储过程sp_executesql,将记录总条数返回给@sum变量set @sumPage=ceiling(@sum/@pageSize)--将@sumPage进一declare @sql nvarchar(1000)--定义sql语句if(@isDesc<>0)--如果需要降序查询
begin
set @colName=@colName
end set @sql='select '+@ReturnCol+' from 
(select top '+str(@pageSize)+' * from 
(select row_number() over (order by '+@colName+') as num,'+@tableName+'.* from '+@tablename+')
as tempTable where num > '+str((@pageIndex-1)*@pageSize)+')
as tmp 'if(@where<>'')--如果where条件不为空
begin
set @sql=@sql+' where '+@where
end
--if(@areaId<>'')
-- begin
-- set @sql=@sql+' where '+@where + 'and AreaId= ' + @areaId
--    endexec(@sql)--执行sql语句return @sumPage--返回总页数
godeclare @sumPage int
declare @sum int
exec @sumPage=pageQuery
'Id,TelType,ClientId,AreaId,DeptName,OutStoreDate,TelDate,ClientPerson',--返回的列
30,--每页存放的数据数量
'Id',--照指定列排序
'Tbl_InputInfor',--对指定表操作
1,--第几页
1,--非0代表降序
'',--where条件
--'SH',
@sum outputselect @sumPage as '总页数'
select @sum as '总记录'
报错如下:
消息 8114,级别 16,状态 5,过程 pageQuery,第 0 行
从数据类型 varchar 转换为 int 时出错。(1 行受影响)
(1 行受影响)
请教各位大侠了~!

解决方案 »

  1.   

    下面这段里是不是少传了第一个参数
    exec @sumPage=pageQuery
    'Id,TelType,ClientId,AreaId,DeptName,OutStoreDate,TelDate,ClientPerson',--返回的列
    30,--每页存放的数据数量
    'Id',--照指定列排序
    'Tbl_InputInfor',--对指定表操作
    1,--第几页
    1,--非0代表降序
    '',--where条件
    --'SH',
    @sum output
      

  2.   

    这样你的第三个参数是 'Id' 当不能转换为int