CREATE procedure ListPage
/*:[百万级]通用存储过程.分页存储过程..返回指定返回条数、指定页数的记录*/
(
@SQL nVARCHAR(4000),--选择的SQL语句
@Page int,--页号
@RecsPerPage int,--返回记录数
@ID VARCHAR(255),--主键
@Sort VARCHAR(255)--排序字段,T9是表别名
)
AS
SET NOCOUNT ON
DECLARE @Str nVARCHAR(4000)
SET @Str='SELECT TOP '+CAST(@RecsPerPage AS VARCHAR(20))+' * FROM ('+@SQL+') T WHERE T.'+@ID+' NOT IN
(SELECT TOP '+CAST((@RecsPerPage*(@Page-1)) AS VARCHAR(20))+' '+@ID+' FROM ('+@SQL+') T9 ORDER BY '+@Sort+') ORDER BY '+@Sort
PRINT @Str
EXEC sp_ExecuteSql @Str
GO
/*:[百万级]通用存储过程.分页存储过程..返回指定返回条数、指定页数的记录*/
(
@SQL nVARCHAR(4000),--选择的SQL语句
@Page int,--页号
@RecsPerPage int,--返回记录数
@ID VARCHAR(255),--主键
@Sort VARCHAR(255)--排序字段,T9是表别名
)
AS
SET NOCOUNT ON
DECLARE @Str nVARCHAR(4000)
SET @Str='SELECT TOP '+CAST(@RecsPerPage AS VARCHAR(20))+' * FROM ('+@SQL+') T WHERE T.'+@ID+' NOT IN
(SELECT TOP '+CAST((@RecsPerPage*(@Page-1)) AS VARCHAR(20))+' '+@ID+' FROM ('+@SQL+') T9 ORDER BY '+@Sort+') ORDER BY '+@Sort
PRINT @Str
EXEC sp_ExecuteSql @Str
GO