sql 分页存储过程
USE EplusSystem --DROP PROC Page
GO
CREATE PROCEDURE Page --分页存储过程
@TableName VARCHAR(100),--表名
@PageSize INT,--页大小
@PageIndex INT,--页号
@StrWhere VARCHAR(100),--条件
@OrderField VARCHAR(100)--排列
AS
DECLARE @IdCount INT
DECLARE @Where VARCHAR(100)
DECLARE @Order VARCHAR(100)
SET @IdCount=@PageSize*@PageIndex
IF(@StrWhere!='')
SET @Where=' AND '+@StrWhere
ELSE
SET @Where=''
IF(@OrderField!='')
SET @Order=' ORDER BY '+@OrderField
ELSE
SET @Order=''
EXEC ('SELECT TOP '+ @PageSize +' * FROM '+@TableName+' WHERE Id NOT IN (SELECT TOP '+@IdCount+' Id FROM '+@TableName+' ORDER BY Id ASC) '+@Where+@Order)
存储过程中要注意空格号!!!!