|
Posted on
2009-05-03 18:27
X龙
阅读( 179)
评论()
编辑
收藏
举报
Code
Create procedure [dbo].[P_Page_Data]
(
@tableName varchar(80),
@currentPageIndex int=1 ,
@pageSize int=10,
@countRecord int output
)
As
declare @currentPageSize int
DECLARE @sqlStr nvarchar(1000)
declare @SQL nvarchar(50)
SET @SQL= N'select @R=count(*) from '+@tableName
EXEC SP_EXECUTESQL @SQL, N'@R BIGINT OUTPUT', @R=@countRecord output;
set @currentPageSize=@currentpageindex * @pagesize;
Begin
set @sqlStr='SELECT * FROM (SELECT ROW_NUMBER() OVER (ORDER BY auto_id desc) AS rownum, * FROM '+@tableName+' ) a WHERE rownum >= ' + Convert(varchar(50),@currentPageSize-@pagesize+1) + 'and rownum <= ' + Convert(varchar(50),@currentPageSize)
EXEC (@sqlStr)
End
|