数据库STUDB 表student
alter proc pageStu(@tableNanme nvarchar(20),@whereName nvarchar(200),@orderBy nvarchar(50),@pageIndex int,@pageSize int,@pageCount int out)
as
begin
declare @stratCount int,@endCount int;
declare @sqlWhere nvarchar(500);
set @stratCount=(@pageIndex-1)*@pageSize+1;
set @endCount=@stratCount+@pageSize-1;
set @sqlWhere='select * from (select ROW_NUMBER() over (order by '+@orderBy+') as rowid, * from '+@tableNanme+' where 1=1) as t where t.rowid between '+TRIM(STR(@stratCount))+' and '+TRIM(STR(@endCount))+'';
--
declare @strCount nvarchar(200);
set @strCount='select @pageCount=count(*) from '+@tableNanme+'';
--
exec sp_executesql @strCount,N'@pageCount int out',@pageCount out;
exec(@sqlWhere);
end
declare @sqlcount int;
exec pageStu 'student','','sid','1','3',@sqlcount out
select @sqlcount