万能SQL分页语句

1.select top 每页显示的记录数 * from topic where id not in  
2. (select top (当前的页数-1)×每页显示的记录数 id from topic order by id desc)   
3. order by id desc  


存储过程分页

create procedure tb_operator_proc    
@pageSize int,      --每页的记录数    
@index int          --从第几条记录开始    
as   
  begin   
  set nocount on        
declare @sql nvarchar(3000)    
if @index>@pageSize    
     begin   
  set @index = @index - @pageSize    
       set @sql='select top '+cast (@pageSize as varchar(8))+' * from tb_operator where id>(    
          select max(id) from (select top '+cast (@index as varchar(8))+' id from tb_operator order by id)     
        as t)    
        order by id'    
  end   
else   
  begin   
      set @sql = 'select top '+cast (@pageSize as varchar(8))+'* from tb_operator order by id'    
  end   
execute sp_executesql @sql   --调用系统存储过程忧化效率     
set nocount off   
end 

你可能感兴趣的:(sql)