如何在变量中存储标量函数的值?

时间:2018-01-23 14:18:21

标签: sql sql-server tsql

我想写一个单元测试,如下图所示:

-- Test name
     SET @TestName        = 'EastersMonday'
     -- Set unit-test StartTime
     SET @UnitTestStart    = GETDATE()
     -- Result
     SET @RequiredResult      = 20180402
     -- Method call
     SET @FunctionResult = DWH_Staging.dim.GetEasters (@Year = 2018, @Day = 'Monday', @CountryID = 1) -- "An insufficient number of parameters were supplied..."
     -- Evaluation
     SELECT @TestResult = IIF(@RequiredResult = @@ROWCOUNT,1,0)
     -- Set unit-test EndTime
     SET @UnitTestEnd = GETDATE()
     -- Log
     INSERT INTO @Result (TestName,TestResult,TestStart,TestEnd) VALUES (@TestName,@TestResult,@UnitTestStart,@UnitTestEnd)

到标量函数,定义为

CREATEFUNCTION [dim].[GetEasters](@Year AS INTEGER,@Day VARCHAR(15),@CountryID TINYINT)
RETURNS INT

单元测试解析器引发错误

  

"提供的参数数量不足......"

这很好用:

DECLARE @Result int
SET @Result = dim.GetEasters(2018, 'Monday', 1)
SELECT @Result  

我做错了什么?

0 个答案:

没有答案
相关问题