您的位置:首页 > 其它

常用分页存储过程

2008-12-02 10:47 316 查看
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

DROP TABLE #PageIndex
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: