SQL Server 2008 paging methods?

前端 未结 7 555
傲寒
傲寒 2020-11-29 06:23

I have to work with a potentially large list of records and I\'ve been Googling for ways to avoid selecting the whole list, instead I want to let users select a page (like f

相关标签:
7条回答
  • 2020-11-29 06:53

    Try this

    Declare @RowStart int, @RowEnd int;
    
    
    SET @RowStart = 4;
    SET @RowEnd = 7; 
    
    With MessageEntities As 
    (
        Select ROW_NUMBER() Over (Order By [MESSAGE_ID]) As Row, [MESSAGE_ID]
        From [TBL_NAFETHAH_MESSAGES]
    )
    Select  m0.MESSAGE_ID, m0.MESSAGE_SENDER_NAME,
            m0.MESSAGE_SUBJECT, m0.MESSAGE_TEXT
    From MessageEntities M
        Inner Join [TBL_NAFETHAH_MESSAGES] m0 on M.MESSAGE_ID = m0.MESSAGE_ID
    Where M.Row Between @RowStart AND @RowEnd
    Order By M.Row Asc
    GO
    
    0 讨论(0)
提交回复
热议问题