I want to create stored procedure with pagination along with top 100 against a subset of a table. For example in a table(ex:employee table) with more than 3,000,000 records, I want to take the top 100,000 records and do the pagination. I'm able to do the pagination using below script, but I want to take the top 100,000 records and do the pagination.
DECLARE @currentPageNo int,@takeData int
SET @currentPageNo =1
SET @takeData = 10
SELECT DISTINCT emp.empid,emp.name,s.Salary,
FROM Employee emp
LEFT OUTER JOIN salary S ON emp.empid=S.empid
where emp.empid=12
ORDER BY emp.empid desc
OFFSET (@currentPageNo - 1) * @takeData ROWS
FETCH NEXT @takeData ROWS ONLY
I need some suggestions on how this can be achieved. I'm using SQL Server 2012.