Create proc xp_Pager
@tableName varchar(20),
@pageSize int,
@pageIndex int,
@primaryKey varchar(20),
@strWhere varchar(500)
as
declare @sqlStr varchar(2000)
if(@strWhere!='')
begin
set @sqlStr='select top '+cast(@pageSize as varchar(10))
+' * from '+@tableName
+' where '+@primaryKey
+' not in (select top '+cast((@pageSize*(@pageIndex-1)) as varchar(10))+' '+@primaryKey
+' from '+@tableName
+' where '+@strWhere+' order by '+@primaryKey
+') and '+@strWhere+' order by '+@primaryKey
end
else
begin
set @sqlStr='select top '+cast(@pageSize as varchar(10))
+' * from '+@tableName
+' where '+@primaryKey
+' not in (select top '+cast((@pageSize*(@pageIndex-1)) as varchar(10))+' '+@primaryKey
+' from '+@tableName
+' order by '+@primaryKey
+') order by '+@primaryKey
end
exec(@sqlStr)