0

Can you help me write SQL sentence that choose many rows ? It is about pagination - parameters are size of page (=number of rows in one bucket) and number of page to choose (many rows = size of page).

For me, it should look like:
cnt =select count(*) from table
select * from table limit x,y
x=cnt/size_of_page * number_of_page
y=(cnt/size_of_page * number_of_page)+size_of_page

I am not sure if I am correct. Can you help me with translating it into sql server ?

  • Which version of sql server you are using? – Tharunkumar Reddy Nov 17 '16 at 06:36
  • I need for 2008 and 2015 version –  Nov 17 '16 at 06:36
  • 1
    pagination for 2008 here: http://stackoverflow.com/questions/2244322/how-to-do-pagination-in-sql-server-2008 ... for 2015 `OFFSET` and `FETCH` were introduced, which behave similarly to `LIMIT` in MySQL and Postgres. – Tim Biegeleisen Nov 17 '16 at 06:37
  • 2
    Possible duplicate of [What is the best way to paginate results in SQL Server](http://stackoverflow.com/questions/109232/what-is-the-best-way-to-paginate-results-in-sql-server) – Preetika Kaur Nov 17 '16 at 06:54
  • I don't think there is a version called 2015 in sql server. there is 2012, 2014 and 2016, there is also 2005, but I've never heard of 2015. Also, `limit` is used in MySql, not in Sql Server, are you sure you are asking about the correct database? – Zohar Peled Nov 17 '16 at 08:07
  • Yes, I was not correct. I meant 2016 version –  Nov 17 '16 at 10:57

0 Answers0