/*
用存储过程实现的分页程序
*/
CREATE procedure Department_pagination 
@SelectStr nvarchar(1000),
@ColumnStr nvarchar (1000),
@OrderStr nvarchar (1000),
@CurrentPage int,
@PageCount int
as
declare @TimeName nvarchar(25)
declare @TableStr nvarchar(1000)select @TimeName = convert(nvarchar(23), getdate(), 121)
set @TimeName = REPLACE(@TimeName, '.', '')
set @TimeName = REPLACE(@TimeName, ':', '')
set @TimeName = REPLACE(@TimeName, '-', '')
set @TimeName = REPLACE(@TimeName, ' ', '')select @TableStr='create table ##Tab' + @TimeName + '(wb int identity,'
exec(@TableStr+@ColumnStr+')')
exec('insert into ##Tab' + @TimeName + ' ' + @SelectStr + ' order by ' + @OrderStr)
exec('select * from ##Tab' + @TimeName + ' where wb between ((' + @CurrentPage + '-1)*' + @PageCount + '+1) and ' + @CurrentPage + '*' + @PageCount + ' order by wb')
exec('drop table ##Tab' + @TimeName)
GO参数1:select语句。2:字段列表。3:排序字段。4:当前页。5每页数目

解决方案 »

  1.   

    如果,votepl.id是自动编号
    用 ORDER BY votepl.id 或者
    ORDER BY votepl.id desc 或者
    干脆什么都不 ORDER BY 
    应该是一样的
      

  2.   

    id是自动编号,但是我现在只有用order by votepl.id才好用,不加这句每次选出来的数据是一样的,加了desc每次选出来的数据也是一样的.
      

  3.   

    你的id,不是作为参数传递过来的吗,这样生成记录的id字段的值都是一样的,你进行排序
    有什么作用?
      

  4.   

    我传的@voteid是表是这个记录是属于哪个主记录的,和他对应的记录很多的.