Consultas de prueba:
declare @tamPagina int declare @pagina int set @tamPagina = 10 set @pagina = 1 if @pagina > 0 begin select ProductID, ProductNumber, Name, ListPrice from Production.Product order by ProductNumber -- Skip offset ((@pagina - 1) * @tamPagina) rows -- Saltar N registros -- take fetch next @tamPagina rows only -- Toma N registros end else begin select ProductID, ProductNumber, Name, ListPrice from Production.Product where 0=1 end go;
Consultas para crear el procedimiento almacenado
create procedure dbo.pa_ListadoProductos ( @tamPagina int = 0, @pagina int = 0 ) as begin if @pagina > 0 begin select ProductID, ProductNumber, Name, ListPrice from Production.Product order by ProductNumber -- Skip offset ((@pagina - 1) * @tamPagina) rows -- Saltar N registros -- take fetch next @tamPagina rows only -- Toma N registros end else begin select ProductID, ProductNumber, Name, ListPrice from Production.Product where 0=1 end end
Consultas para probar el procedimiento almacenado
select ProductID, ProductNumber, Name, ListPrice from Production.Product order by ProductNumber exec pa_ListadoProductos 10, 2
Vídeo del proceso anterior: