通用分页存储过程

CREATE PROCEDURE [dbo].[sp_getdatebyPageIndex]

@pageindex int=0,

@pagesize int=10,

@table nvarchar(100),

@columns nvarchar(500),

@condition nvarchar(300),-- and ,or

@pk nvarchar(100) AS BEGIN   

DECLARE @sql nvarchar(1000)   

SET @sql=' select top '+cast(@pagesize AS nvarchar(10))+''+@columns + ' from '+@table+   ' where '+@pk+' not in (select top '+ cast(@pageindex*@pagesize AS nvarchar(10))+ ' '+ @pk +' from '+ @table+' where 1=1 '+@condition+')' +@condition

--   PRINT @sql  

 EXEC(@sql) END

你可能感兴趣的:(通用分页存储过程)