获取用户记录的分页存储过程
Code
USE [SpaceBuilder]
GO
/****** 对象: StoredProcedure [dbo].[wl_Users_GetSet] 脚本日期: 12/02/2008 10:49:20 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/* 获取用户记录,并用于分页显示 */
CREATE PROCEDURE [dbo].[wl_Users_GetSet]
(
@sqlPopulate ntext,
@PageIndex int,
@PageSize int,
@UserType smallint,
@TotalRecords int output
)
AS
SET Transaction Isolation Level Read UNCOMMITTED
SET NOCOUNT ON
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
if (@UserType = 1)
SELECT
U.*
FROM
wl_vw_PersonUsers_FullUser U (nolock),
#PageIndex
WHERE
U.UserID = #PageIndex.ItemID AND
#PageIndex.IndexID > @PageLowerBound AND
#PageIndex.IndexID < @PageUpperBound
ORDER BY
#PageIndex.IndexID
else
SELECT
U.*
FROM
wl_vw_CompanyUsers_FullUser U (nolock),
#PageIndex
WHERE
U.UserID = #PageIndex.ItemID AND
#PageIndex.IndexID > @PageLowerBound AND
#PageIndex.IndexID < @PageUpperBound
ORDER BY
#PageIndex.IndexID
DROP TABLE #PageIndex
USE [SpaceBuilder]
GO
/****** 对象: StoredProcedure [dbo].[wl_Users_GetSet] 脚本日期: 12/02/2008 10:49:20 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/* 获取用户记录,并用于分页显示 */
CREATE PROCEDURE [dbo].[wl_Users_GetSet]
(
@sqlPopulate ntext,
@PageIndex int,
@PageSize int,
@UserType smallint,
@TotalRecords int output
)
AS
SET Transaction Isolation Level Read UNCOMMITTED
SET NOCOUNT ON
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
if (@UserType = 1)
SELECT
U.*
FROM
wl_vw_PersonUsers_FullUser U (nolock),
#PageIndex
WHERE
U.UserID = #PageIndex.ItemID AND
#PageIndex.IndexID > @PageLowerBound AND
#PageIndex.IndexID < @PageUpperBound
ORDER BY
#PageIndex.IndexID
else
SELECT
U.*
FROM
wl_vw_CompanyUsers_FullUser U (nolock),
#PageIndex
WHERE
U.UserID = #PageIndex.ItemID AND
#PageIndex.IndexID > @PageLowerBound AND
#PageIndex.IndexID < @PageUpperBound
ORDER BY
#PageIndex.IndexID
DROP TABLE #PageIndex