CREATE PROCEDURE [dbo].[sp_GetPageWiseData]
(
@tableName sysname,
@orderColumn nvarchar(100),
@PageIndex INT = 1,
@PageSize INT = 10,
@RecordCount varchar(10) OUTPUT
)
AS
BEGIN
SET NOCOUNT ON;
DECLARE @query varchar(2000),
@minimumIndex varchar(5),
@maximumIndex varchar(5)
SET @minimumIndex=convert(varchar,(@PageIndex - 1) * @PageSize + 1)
SET @maximumIndex=convert(varchar,@PageIndex * @PageSize)
SET @query='SELECT ROW_NUMBER() OVER(ORDER BY ' + @orderColumn + ' ASC)AS RowNumber,* INTO #Results FROM ' + @tableName + ';
SELECT ' + @RecordCount + '=COUNT(*) FROM #Results;
SELECT * FROM #Results WHERE RowNumber BETWEEN ' + @minimumIndex + ' AND ' + @maximumIndex + ';
DROP TABLE #Results'
Exec (@query)
END
这里的问题是当程序执行时,输出参数@RecordCount
显示 NULL 值。
为什么?
请解释。谢谢