我无法深入了解为什么下面代码中的输出变量返回 null。我已经在调试中逐步完成了它,并复制/运行了 sql 语句,它确实返回了预期值。但是当我运行它时,它只是空的。任何帮助都会很棒..
ALTER PROCEDURE [dbo].[spCountOfMostRecentByTableName] @table VARCHAR(120),
@count BIGINT OUTPUT
AS
BEGIN
DECLARE @parameters NVARCHAR(100)
SET @parameters = '@count BIGINT OUTPUT'
DECLARE @date DATE = dbo.MostRecentTradeDateForDataDownload()
DECLARE @sql NVARCHAR(MAX) = N'
SELECT COUNT(ID)
FROM ' + @table +
' WHERE DateAdded = ''' + CAST(@date AS CHAR) + '''';
EXEC sp_executesql @sql, @parameters, @count = @count OUTPUT
SELECT @count
END