Here's the paging sproc I'm using:
ALTER PROCEDURE ams_ArticlePage (
@Page int,
@RecsPerPage int,
@ContainerID bigint
) AS
-- Paging code hacked 'n' slashed from http://www.aspfaqs.com/webtech/062899-1.shtml
-- We don't want to return the # of rows inserted
-- into our temporary table, so turn NOCOUNT ON
SET NOCOUNT ON
--Create a temporary table, a direct copy of ams_Articles
CREATE TABLE #TempItems (
TempID bigint IDENTITY (1, 1),
[ID] bigint NOT NULL,
[InContainer] bigint NOT NULL,
[CompositeName] varchar(200) NOT NULL,
[Name] nvarchar(100) NOT NULL,
Username nvarchar(50) NOT NULL
-- and about 15 other fields (not shown for readability)
)
-- Insert the rows from tblItems into the temp. table
INSERT INTO #TempItems (
[ID],[InContainer],[CompositeName], [Name] Username
) SELECT
ams_Articles.[ID],[InContainer],[CompositeName], [Name] Username
FROM
ams_Articles
INNER JOIN ams_Users ON ams_Articles.InUser = ams_Users.[ID]
WHERE
ams_Articles.InContainer = @ContainerID
ORDER BY
ams_Articles.[ID] DESC
-- Find out the first and last record we want
DECLARE @FirstRec bigint, @LastRec bigint
SELECT @FirstRec = (@Page - 1) * @RecsPerPage
SELECT @LastRec = (@Page * @RecsPerPage + 1)
-- Now, return the set of paged records, plus, an indiciation of if we have more records or not!
SELECT
*,
MoreRecords = (
SELECT
COUNT(*)
FROM
#TempItems TI
WHERE
TI.[TempID] >= @LastRec
)
FROM
#TempItems
WHERE
[TempID] > @FirstRec
AND
[TempID] < @LastRec
-- Turn NOCOUNT back OFF
SET NOCOUNT OFF
Thread Closed
This thread is kinda stale and has been closed but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.