user1921306
user1921306

Reputation: 1

stored function returning NULL

I create the following function on MASTER db so you can replicate it without problems

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

When i call my function in this way "select dbo.sf_getdateaggiogap('sysrscols','system_table') as datanext from sys.all_objects where name ='sysrscols'" the result is always null the code run correctly but the query's result is always null. where am i wrong?

THANKS

Upvotes: 0

Views: 76

Answers (1)

bummi
bummi

Reputation: 27377

Missing Size for parameters ....

Alter  FUNCTION [dbo].[sf_GetDateAggioGAP]
                   (@name varchar(max),@type_desc VARCHAR(max))

Upvotes: 4

Related Questions