Click here to Skip to main content
15,894,180 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi,
i want to implement the paging, i write a procedure for data,in that procedure i want implement the paging.if You know how to implement the paging in stored procedure in sqlserver.
Thanks in Advance.
Posted

SQL
CREATE PROCEDURE [dbo].[asp_Pagingtest]
( @index as int     =1  )

Begin

--something
--something

--something

 Declare @StartIndex as int=((@index-1)*10)+1
Declare @EndIndex as Int=@index*10


With CTE_Count as
(Select EmpId,ROW_NUMBER() OVER (ORDER BY  S.LastName) AS RowNumber
 from table_temp )
Select * from table_temp where EmpId in (select EmpId from CTE_COunt where rownumber between @StartIndex  and @EndIndex)

END


Here @Index is the pageno by default, we have to dispaly first page. EmpId is the primary key for the table where i am going to pull records
 
Share this answer
 
v2
Put this query in store procedure
SQL
select * from
(
select row_number over(partition by id,name order by id,name) as index_no,--this will assign row no 1,2,3,...
id,name
from tbl 
) as a
where index_no>@StartIndex --pass here from-to record-no range.
      and index_no<@EndIndex



pass parameters '@StartIndex' & '@EndIndex' range while clicking button.
eg. 1-10, 11-20,...
Happy Coding!
:)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900