create proc pageRepeat
@tblname varchar(255), 
@fldname varchar(255), 
@pageSize int,
@pgIndex int
as
declare @strSQL nvarchar(4000), 
@totalCounts int,
@pageCounts intset @strSQL ='select @totalCounts=count(*) from '+@tblnameexec sp_executesql @strSQL,'@totalCounts int',@totalCounts outset @pageCounts=(@totalCounts/@pageSize)if @pgIndex = 1set @strSQL='select top'+cast(@pageSize as varchar)+'* from'+@tblname+' order by '+@fldname+' desc'elseset @strSQL='select top '+cast(@pageSize as varchar)+'* from '+@tblname+' where '+@fldname
+' >(select '+cast(@pageSize*(@pageCounts-@pgIndex) as varchar)+@fldname+' from '+@tblname
+' order by  '+@fldname+' desc) order by  '+@fldname+' asc 'exec sp_executesql @strSQL
服务器: 消息 214,级别 16,状态 3,过程 sp_executesql,行 17
过程需要参数 '@parameters' 为 'ntext/nchar/nvarchar' 类型。
谢谢.

解决方案 »

  1.   

    大家能把我这个程序改一下,.只要我能这样运行就可以了exec pagerepeat '表名','字段名',10,1里面很多东西特别是类型 .我很容易错.
      

  2.   

    @tblname,@fldname 设成 nvarchar类型.set @strSQL=N'select @totalCounts=count(*) from '+@tblname
    再执行
    exec sp_executesql @strSQL
      

  3.   

    直接把@parameters设为nvarchar类型就行了
      

  4.   

    写错,应该是@strSQL拼接的时候强制转换一下就行了
      

  5.   

    这样就可以了。exec sp_executesql @strSQL,N'@totalCounts int',@totalCounts out