SQL 服务器用户定义函数出错

SQL Server User define function giving error

我在 SQL 服务器

中创建以下 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

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

select
 dbo.Fn_dd('2020-01-02','2020-02-08')
from dbo.Txns

错误信息

Cannot find either column "dbo" or the user-defined function or aggregate "dbo.Fn_dd", or the name is ambiguous.

知道为什么吗?

你的函数returns一个table。您不能在 SELECT 中使用它;您必须在 FROM:

中使用它

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