Code USE [SpaceBuilder]
GO /****** 对象: StoredProcedure [dbo].[wl_UserVisits_GetSet] 脚本日期: 12/02/2008 10:41:44 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO /*获取访客记录,并用于分页显示*/
Create PROCEDURE [dbo].[wl_UserVisits_GetSet]
(
@sqlPopulate ntext,
@PageIndex int,
@PageSize int,
@TotalRecords int output
)
AS
SET Transaction Isolation Level Read UNCOMMITTED
DECLARE @PageLowerBound int
DECLARE @PageUpperBound int
-- Set the page bounds
SET @PageLowerBound = @PageSize * @PageIndex
SET @PageUpperBound = @PageLowerBound + @PageSize +1
-- Create a temp table to store the select results
CREATE TABLE #PageIndex
(
IndexID int IDENTITY (1, 1) NOT NULL,
ItemID int
)
CREATE INDEX page_index ON #PageIndex(IndexID)
insert into #PageIndex (ItemID)
exec (@sqlPopulate)
SET @TotalRecords = @@rowcount
select V.*
from wl_UserVisits V (nolock) inner join #PageIndex on V.VisitID = #PageIndex.ItemID where #PageIndex.IndexID > @PageLowerBound and #PageIndex.IndexID < @PageUpperBound
order by #PageIndex.IndexID