create proc SP_Pagu
(
@pageIndex int,
@pageSize int,
@strWhere nvarchar(2000),
@rowCount int out
)
as
begin
declare @strSql nvarchar(3000);
declare @countSql nvarchar(3000);
declare @star int;
declare @end int;
set @star=(@pageIndex-1)*@pageSize;
set @end=@star+@pageSize+1;
set @countSql='select @rowCount=count(*) from Limit';
set @strSql='select * from (select ROW_NUMBER() over(order by ID) as tid ,*from Limit) t where tid > '+str(@star)+' and tid< '+str(@end)+'';
if(@strWhere<>'')
begin
set @strSql+=@strWhere;
end
exec (@strSql)
print(@strSql)
exec sp_executesql @countSql,N'@rowCount int output',@rowCount output
end
declare @count int
exec SP_Pagu 2,2,'',@count output
select count(*) from Limit