简单分页

CREATE PROC pain
( 
    @PageSize   int ,                   -- Page size  
    @PageIndex  int                 -- Page index  
)
AS

    declare @strBeginNum INT   --起始页
    declare @strEndNum  int  --结束页                               
    declare @strSQL   nvarchar(1000)      -- main sql                                                                 
    SET @strBeginNum= (@PageIndex - 1) * @PageSize + 1 --(总页数-1)*10+1 每页显示的条数和当前页马   
                                                       --                                                                                       
    SET @strEndNum=@strBeginNum + @PageSize -1 --总数*条数                                
     --实现分页查询                            
      SET @strSQL= 'SELECT * FROM 
      (    SELECT ROW_NUMBER() OVER (ORDER BY id )num,* FROM SysMenu)  a WHERE num BETWEEN ' +convert(nvarchar,@strBeginNum)+'  and '+convert(nvarchar,@strEndNum) +''
      EXEC(@strSQL)
      PRINT(@strSQL)

  GO
      
      EXEC pain 10,5
      
      DROP PROC pain

 

posted @ 2015-04-29 13:42  清空回声  阅读(99)  评论(0编辑  收藏  举报