初学者的一个问题,请看下面的存储过程,PageNumber和PageSize都没赋值怎么下面就可以用了?
CREATE PROCEDURE sp_Forums_GetTopicsByPage
@ForumID int,
@PageNumber int,
@PageSize int
AS
-- create a temporary table with the columns we are interested in
CREATE TABLE #TempTopics
(
ID int IDENTITY PRIMARY KEY,
TopicID int,
Subject varchar(100),
AddedDate datetime,
TopicReplies int,
TopicLastReplyDate datetime,
TopicLastPostDate datetime,
MemberID int,
MemberName varchar(15),
Email varchar(50),
ShowEmail bit
)
-- fill the temp table with all the topics for the
-- specified forum retrieved from the v_Forums_Topics view
INSERT INTO #TempTopics
(
TopicID,
Subject,
AddedDate,
TopicReplies,
TopicLastReplyDate,
TopicLastPostDate,
MemberID,
MemberName,
Email,
ShowEmail
)
SELECT
TopicID,
Subject,
AddedDate,
TopicReplies,
TopicLastReplyDate,
TopicLastPostDate,
MemberID,
MemberName,
Email,
ShowEmail
FROM
v_Forums_Topics WHERE ForumID = @ForumID ORDER BY TopicLastPostDate Desc
-- declare two variables to calculate the range of records to extract for the specified page
DECLARE @FromID int
DECLARE @ToID int
-- calculate the first and last ID of the range of topics we need
SET @FromID = ((@PageNumber - 1) * @PageSize) + 1
SET @ToID = @PageNumber * @PageSize
-- select the page of records
SELECT TopicID, Subject, AddedDate, TopicReplies, TopicLastReplyDate, TopicLastPostDate, MemberID, MemberName, Email, ShowEmail
FROM #TempTopics WHERE ID >= @FromID AND ID <= @ToID
GO