我希望將總行數作爲輸出參數,稍後將從C#訪問。這個查詢給出了一個錯誤 - 無效的對象名稱TBL'如何從存儲過程中恢復輸出參數
ALTER PROCEDURE [dbo].[GetOrderDetails]
@SortOrder nchar(10),
@ColName nvarchar(20),
@StartIndex int,
@PageSize int,
@RecordCount int output
AS
BEGIN
SET NOCOUNT ON;
DECLARE @Query nvarchar(MAX),
@Params nvarchar(MAX)
SET @StartIndex = (@PageSize * (@StartIndex-1))+1
SET @PageSize = @StartIndex + @PageSize - 1
SET @Params = '@StartIndex int,
@PageSize int,
@RecordCount int'
SET @Query = 'WITH TBL AS
(
SELECT OD.OrderID,OD.ProductID,P.ProductName,OD.UnitPrice,
OD.Quantity,OD.Discount
FROM [Order Details] OD
LEFT JOIN Products P ON OD.ProductID = P.ProductID
)
SELECT @RecordCount = COUNT(*) FROM TBL ;
SELECT * FROM
(
SELECT ROW_NUMBER() OVER(ORDER BY '[email protected]+')Row, *
FROM TBL
)TEMP
WHERE Row BETWEEN @StartIndex AND @PageSize
ORDER BY Row '[email protected]
execute sp_Executesql @Query,@Params,@RecordCount,@StartIndex,@PageSize
END
'='附近語法不正確。此外,它仍然是一個o/p參數吧? – Ruby