常用分页存储过程
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
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
相关文章推荐
- C#中常用的分页存储过程小结
- 常用的分页存储过程
- (转)几种常用存储过程分页方法
- C#中常用的分页存储过程
- 记录一条自己常用的分页存储过程
- asp.net中常用到的SQL分页存储过程
- 几种常用存储过程分页方法
- 常用存储过程分页实现方法的性能比较
- SQL常用分页存储过程
- C#中常用的分页存储过程总绪
- SQL分页常用的两个存储过程
- C#中常用的分页存储过程小结
- 项目中的几个常用的分页存储过程
- [原创]存储过程DataGrid分页及注意点
- SQL分页存储过程中排序问题
- 简单有效的分页存储过程
- C#.NET SQLServer数据库分页函数,包含存储过程和C#代码
- Oracle中的分页存储过程
- 分页存储过程
- sql 多表联合分页存储过程例子