0

我在 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'",结果始终为空,代码运行正确,但查询的结果始终为空。我哪里错了?

谢谢

4

1 回答 1

4

缺少参数的大小 ....

Alter  FUNCTION [dbo].[sf_GetDateAggioGAP]
                   (@name varchar(max),@type_desc VARCHAR(max))
于 2012-12-21T11:02:06.920 回答