SQL Server 用户定义函数给出错误

Jon*_*Way 0 sql sql-server sql-server-2012

我在 SQL Server 中创建以下 UDF

CREATE Function [Fn_dd]
(@InputstartDate Date, @InputendDate Date)
returns @AllDates Table
    (AllDate Date)
As
Begin
    Declare @startDate date
    Declare @endDate date
    Declare @rDate date
    set @startDate  = @InputstartDate
    set @EndDate  = @InputendDate

    while (@startDate <=  @endDate)
    Begin
        insert into @AllDates values (@startDate )
        set @startDate = DATEADD(dd,1,@startDate)
    End
return
End
GO
Run Code Online (Sandbox Code Playgroud)

但是当我在数据中使用它时会出现错误

select
 dbo.Fn_dd('2020-01-02','2020-02-08')
from dbo.Txns
Run Code Online (Sandbox Code Playgroud)

错误信息

Cannot find either column "dbo" or the user-defined function or aggregate "dbo.Fn_dd", or the name is ambiguous.
Run Code Online (Sandbox Code Playgroud)

知道为什么吗?

Geo*_*tis 5

您的函数返回一个表。SELECT您不能在;中使用它 你必须在以下位置使用它FROM

select * FROM dbo.Fn_dd('2020-01-02','2020-02-08')