Pagination query for mssql server 2008 Throwing Incorrect syntax near 'OFFSET'

前端 未结 4 1863
醉话见心
醉话见心 2021-01-15 05:51

I am Working on pagination in jsp(and i am new to writing sql).

I done my research and found simple queries from

pagination in SQL server 2008 and How to d

4条回答
  •  再見小時候
    2021-01-15 06:06

    DECLARE @Page int
    SET @Page = 2
    DECLARE @Amount int
    SET @Amount = 25
    SELECT * FROM (
    SELECT ROW_NUMBER() OVER(ORDER BY group_id) AS rownumber, * FROM table_name 
    WHERE Column LIKE '%Search_Value%') as somex  
    WHERE  rownumber >= (@Page+1)* @Amount-(@Amount - 1) AND rownumber <= (@Page+1) * @Amount
    

    I took it one step further. Added some variables to make inputting the information a little better. At my company we have older databases so this feed helped me a lot.

提交回复
热议问题