Click here to Skip to main content
11,709,366 members (40,315 online)
Click here to Skip to main content

Other Row Paging Technique Using T-SQL

, 27 Apr 2005 23.5K 24
Rate this:
Please Sign up or sign in to vote.
Simple Row Paging Using T-SQL at Stored Procedure


When we work with small data, our web page look so fine displaying Record. But when the data getting large, we will found Mr. Time Out Coming to say "Sorry Expired".

This method is different than other paging method. By using stored procedure we can get a table result that contain specific row rather than get the entire table.

Here the stored procedure routin :

Declare @ActivePage as BigInt = 1
Declare @PageCount as BigInt = 10
Declare @StartDate as DateTime
SET @StartDate = GetDate()

--DECLARE @MidRow as BigInt
DECLARE @TotalRow as BigInt
DECLARE @TotalPage as BigInt
DECLARE @MidRow as BigInt
Select @TotalRow = Count(PartNumber) From Master_Part WITH (NOLOCK)
SET @MidRow = Round(@TotalRow/2,0)
SET @TotalPage = Round(@TotalRow / @PageCount,0)
IF @TotalRow > (@TotalPage * @PageCount) SET @TotalPage = @TotalPage + 1

DECLARE @RowPos as BigInt
DECLARE @ID as VarChar(100)
SET @RowPos = (@PageCount * @ActivePage) - @PageCount
IF @RowPos > @MidRow
SET @RowPos = @TotalRow - @RowPos 
SELECT @ID = PartNumber From Master_Part WITH (NOLOCK) ORDER BY PartNumber DESC
SET @RowPos = @PageCount * @ActivePage
SET @RowPos = @RowPos - @PageCount + 1
SELECT @ID = PartNumber From Master_Part WITH (NOLOCK) ORDER BY PartNumber ASC

DECLARE @Part table(TotalPage Int DEFAULT 0, PartNumber VarChar(50), SparePart Char(255), PartOnHand int)
INSERT INTO @PART SELECT 0 as TotalPage, PartNumber,SparePart,PartOnHand FROM Master_Part WITH (NOLOCK) WHERE PartNumber >= @ID ORDER BY PartNumber ASC
UPDATE @Part SET TotalPage = @TotalPage
SELECT * FROM @Part Order By PartNumber
SELECT DateDiff(MilliSecond,@StartDate,GetDate())


Now we can call the stored procedure using common execute Query function.

dim dt = dataset
dt =
DBServices.ExecuteQuery("Get_MasterPart" ,StoredProcedure,Sqlparameter)


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
Indonesia Indonesia
No Biography provided

You may also be interested in...

Comments and Discussions

Generalnice!! Pin
sharaabi23-Aug-05 4:08
susssharaabi23-Aug-05 4:08 
GeneralBeware using this Pin
toticow28-Apr-05 0:28
membertoticow28-Apr-05 0:28 
I was using a method similar to this, but discovered a problem with SET ROWCOUNT.

I suggest reading SQL Server Books Online - SET ROWCOUNT

The problem is setting the rowcount is global, and if you have other queries running after this one that dont set rowcount, they will be affected by whatever the previous rowcount was set too. This can cause a very hard bug to find. Books Online suggest using TOP instead.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150819.1 | Last Updated 28 Apr 2005
Article Copyright 2005 by bluechip_asia
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid