我在MASTER db上创建了以下函数,因此您可以毫无问题地复制它
ALTER FUNCTION [dbo].[sf_GetDateAggioGAP]
(@name varchar,@type_desc VARCHAR)
RETURNS DATETIME AS
BEGIN
DECLARE @RESULT DATETIME
DECLARE @DATA DATETIME
DECLARE @RIPETI INT
SET @DATA = (SELECT DISTINCT create_date as DATINI FROM sys.all_objects WHERE (name = @name) AND (TYPE_DESC = @type_desc))
SET @RIPETI = (SELECT DISTINCT OBJECT_ID as RIPETI FROM sys.all_objects WHERE (name = @name) AND (TYPE_DESC = @type_desc))
SET @RESULT=@DATA
WHILE @DATA <= getdate()
BEGIN
SET @DATA=dateadd(month,@RIPETI,@DATA)
IF @DATA > GETDATE()
BREAK
ELSE
CONTINUE
SET @RESULT=@DATA
END
RETURN @RESULT
END
当我以这种方式调用我的函数"select dbo.sf_getdateaggiogap('sysrscols','system_table') as datanext from sys.all_objects where name ='sysrscols'"
时,结果始终为null
代码运行正常但查询的结果始终为null。
我哪里错了?
感谢
答案 0 :(得分:4)
缺少参数大小......
Alter FUNCTION [dbo].[sf_GetDateAggioGAP]
(@name varchar(max),@type_desc VARCHAR(max))