CREATE PROC USP_PAGE_ORDER(@PAGE_NO INT,@SIZE INT,@ORDER VARCHAR(20),@COUNT INT OUT)
AS
BEGIN
SET NOCOUNT ON
DECLARE @START INT=(@PAGE_NO-1)*@SIZE+1
DECLARE @END INT= @PAGE_NO*@SIZE;
DECLARE @S VARCHAR(MAX)
CREATE TABLE #TT(ID INT IDENTITY,NAME VARCHAR(MAX))
SET @S='SELECT NAME FROM SYS.OBJECTS ORDER BY NAME '+@ORDER
INSERT INTO #TT EXEC(@S)
SET @COUNT=@@ROWCOUNT
SELECT * FROM #TT WHERE ID BETWEEN @START AND @END
END
CHECK:
DECLARE @TT INT
EXEC USP_PAGE_ORDER 2,10,'ASC',@COUNT=@TT OUT
PRINT @TT
DECLARE @TT INT
EXEC USP_PAGE_ORDER 3,10,'ASC',@COUNT=@TT OUT
PRINT @TT
No comments:
Post a Comment