Video de GenCode Studio y Template para SP Paginado
USE %db-name%
GO
CREATE PROCEDURE %db-schema%.usp_%tablename%_PagedList
(
@pPageNumber int,
@pPageSize int
)
AS SET NOCOUNT ON
BEGIN
DECLARE @ROWSTART int
DECLARE @ROWEND int
DECLARE @pVirtualCount bigint
IF (@pPageNumber IS NULL)
SET @pPageNumber = 1;
SET @ROWSTART = (@pPageNumber - 1)* @pPageSize +1;
SET @ROWEND = @ROWSTART + @pPageSize -1;
SELECT
%db-columns%
,ROW_NUMBER() OVER(ORDER BY %set-db-key%) AS _ROW
INTO #RESULTS
FROM %db-schema%.%tablename%
SET @pVirtualCount = @@ROWCOUNT
SELECT TOP(@pPageSize)
%db-columns%
,@pVirtualCount AS VirtualCount
FROM #RESULTS
WHERE _ROW BETWEEN @ROWSTART AND @ROWEND
ORDER BY %set-db-key%
DROP TABLE #RESULTS
SET NOCOUNT OFF
END
No hay comentarios:
Publicar un comentario