Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL server 2012 pagination with total rows

Author  Topic 

aoriju
Posting Yak Master

156 Posts

Posted - 2013-07-26 : 10:28:09
Hi all

My table contains 1000 records,
i need to know the total record count with the below paging query

SELECT EmpName,Place
FROM EmplyeeDetails ORDER BY Place
OFFSET 10 ROWS FETCH NEXT 10 ROWS ONLY;

How to get

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-07-26 : 10:32:52
If you want it with each record,
SELECT EmpName,Place, count(*) over() as TotalRecords
FROM EmplyeeDetails ORDER BY Place
OFFSET 10 ROWS FETCH NEXT 10 ROWS ONLY;
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2013-07-28 : 10:35:18
or

declare @total int
set @total=(select count(*) from EmplyeeDetails)

SELECT EmpName,Place, @total as total_records
FROM EmplyeeDetails ORDER BY Place
OFFSET 10 ROWS FETCH NEXT 10 ROWS ONLY;


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -