/****** 对象: 存储过程 dbo.P_PageTurn 脚本日期: 2007-5-24 7:50:04 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[P_PageTurn]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[P_PageTurn]
GO
create PROCEDURE P_PageTurn
(
@SQL nVARCHAR(4000), --不带排序语句的SQL语句
@PageIndex int, --页码
@PageSize int, --每页容纳的记录数
@ID VARCHAR(255), --需要排序的不重复的ID号
@Sort VARCHAR(255) --排序字段及规则
)
AS
begin
DECLARE @Str nVARCHAR(4000)
SET @Str='SELECT TOP '+CAST(@PageSize AS VARCHAR(20))+' * FROM( ) T WHERE NOT IN
(SELECT TOP '+CAST((@PageSize*(@PageIndex-1)) AS VARCHAR(20))+' FROM ( ) T9 )
--PRINT @Str
EXEC sp_ExecuteSql @Str
end
GO
DECLARE @Str nVARCHAR(4000)
declare @SQL nVARCHAR(4000) --不带排序语句的SQL语句
declare @PageIndex int --页码
declare @PageSize int --每页容纳的记录数
declare @ID VARCHAR(255) --需要排序的不重复的ID号
declare @Sort VARCHAR(255) --排序字段及规则
select @SQL = 'select * from TQuestion'
select @PageIndex = 3
select @PageSize = 5
select @ID = 'OddNumbers'
select @Sort = ''
SET @Str='SELECT TOP '+CAST(@PageSize AS VARCHAR(20))+' * FROM( ) T WHERE NOT IN
(SELECT TOP '+CAST((@PageSize*(@PageIndex-1)) AS VARCHAR(20))+' FROM ( ) T9 )
print @Str
--EXEC sp_ExecuteSql @Str
--SELECT TOP 10 * FROM( select * from TQuestion) T WHERE T.OddNumbers NOT IN
--(SELECT TOP 0 OddNumbers FROM ( select * from TQuestion ) T9 )
exec P_PageTurn @SQL,@PageIndex,@PageSize,@ID,@Sort
阅读(1676) | 评论(0) | 转发(0) |