CODEDIGEST InstallShield
Home Articles CodeDigest Tutorials InstallShield FAQs
Skip Navigation LinksHome » CodeDigest » Custom Paging Using Sql Server 2005   You are not logged in.
Search
 

Sponsors
InstallShield
 

Sponsored Links
 

Technologies
 

CodeDigest Navigation
 

Technology News
No News Feeds available at this time.
 

Community News
No News Feeds available at this time.
 
Custom Paging Using Sql Server 2005
Custom Paging Using Sql Server 2005
Submitted By Satheesh Babu
On 2/7/2009 7:33:02 AM
Tags: CodeDigest,sql,sql server 2005  

Custom Paging Using Sql Server 2005

Till Sql server 200, we will create a temp table with identity column to implement custom paging. With the introduction of Sql Server 2005, the implementation of Sql 2005 is made simple with the new feature called Row_Number().

 

The below stored procedure will accept the start row index and number of records (PageSize) to return the records that belongs to only that particular page.

 

EXEC GetUsers 1,10

 

Stored Procedure
ALTER PROC [dbo].[GetUsers]
(
@RowIndex INT ,
@MaxRows INT)
AS
DECLARE @StartRow INT
DECLARE @EndRow INT

SET @StartRow = @RowIndex
SET @EndRow = @StartRow + @MaxRows

SELECT * FROM (
SELECT     UserID,FirstName,LastName, ROW_NUMBER() OVER (ORDER BY UserID) AS ROW
FROM         CD_Users) As NumberedUsers
WHERE ROW BETWEEN @StartRow AND (@EndRow-1)

 

Read my article, Custom GridView Paging with ObjectDataSource Control with ASP.Net 2.0


 

Do you have a working code that can be used by anyone? Submit it here. It may help someone in the community!!