views:

58

answers:

2

How to get last page no like stackoverflow.com pagination in Sql server 2005

+2  A: 

Try somethign like this

DECLARE @NumberPerPage INT

SELECT @NumberPerPage = 50

SELECT  CEILING(COUNT(*) / CAST(@NumberPerPage AS FLOAT)) NumberOfPages
FROM    TABLE
astander
Thanks man i ll try it
Pandiya Chendur
+2  A: 

Assuming a page size of 10:

select case when count(*) % 10 = 0 then count(*)/10 else count(*)/10 + 1 end as lastPageNumber from posts;

As you can see, it's a little tedious to do this kind of stuff purely in SQL. What high level language are you using? You can implement the logic in your programming language and then just do this SQL query to get the count of the number of items:

select count(*) from posts;
Asaph
CEILING is exactly what you used there.
astander