Live2D 看板娘 / Demo

sql 分页取数据的存储过程

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE Proc [g].[ListXXX]
    
    @pageNo int = 1,
    @pageSize int = 10
As 
Begin

    Declare @pageEnd int
    Declare @pageStart int

    Set @pageEnd = @pageNo * @pageSize
    Set @pageStart = (@pageNo - 1) * @pageSize

    Select * From (
            Select Row_Number() Over(Order By CreateTime Desc) As Row
            ,[Id]
            ,[Status]
            ,[CreateTime]
            From XXX
            Where [Status] = 2
            
        ) As x
        Where x.Row > @pageStart And x.Row <= @pageEnd

        Select Count(1) From XXX
        Where [Status] = 2
        )

End
                            

 

posted @ 2016-11-18 09:51  MChuang  阅读(122)  评论(0编辑  收藏  举报