2012-12-21 174 views
0

我創建主數據庫下面的函數,因此您可以 運行的代碼正確地複製它沒有問題存儲函數返回NULL

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 @[email protected] 
     WHILE @DATA <= getdate() 
     BEGIN 
     SET @DATA=dateadd(month,@RIPETI,@DATA) 
     IF @DATA > GETDATE() 
     BREAK 
     ELSE 
     CONTINUE 
     SET @[email protected] 
     END 
     RETURN @RESULT 
    END 

當我打電話給我的功能以這種方式"select dbo.sf_getdateaggiogap('sysrscols','system_table') as datanext from sys.all_objects where name ='sysrscols'"結果總是空,但查詢的結果始終爲空。 我在哪裏錯了?

THANKS

+5

您對 – Geert

+0

沒有一個良好的開端你的CapsLock鍵。用'Capslock On'寫作就像大聲呼喊 – Steve

+0

我真的很抱歉。無論如何感謝 – user1921306

回答

4

的參數沒有大小....

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

非常感謝你!現在它的工作正確! – user1921306