我有这个脚本:
CREATE FUNCTION dbo.CheckIfSFExists(@param1 INT, @param2 BIT = 1 )
RETURNS BIT
AS
BEGIN
IF EXISTS ( bla bla bla )
RETURN 1;
RETURN 0;
END
GO
我想以这种方式在程序中使用它:
IF dbo.CheckIfSFExists( 23 ) = 0
SET @retValue = 'bla bla bla';
但我收到错误:
An insufficient number of arguments were supplied for the procedure or function dbo.CheckIfSFExists.
为什么不起作用?
最佳答案
你必须这样调用它
SELECT dbo.CheckIfSFExists(23, default)
来自Technet :
When a parameter of the function has a default value, the keyword DEFAULT must be specified when the function is called in order to retrieve the default value. This behaviour is different from using parameters with default values in stored procedures in which omitting the parameter also implies the default value. An exception to this behaviour is when invoking a scalar function by using the EXECUTE statement. When using EXECUTE, the DEFAULT keyword is not required.
关于tsql - T-SQL - 具有默认参数的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8358315/