首页 > 解决方案 > Cannot find either column "dbo" or the user-defined function or aggregate "dbo.fnCustomDate", or the name is ambiguous

问题描述

I working on a basic function and tried executing but it doesn't work and throws the below error "Cannot find either column "dbo" or the user-defined function or aggregate "dbo.fnCustomDate", or the name is ambiguous."

Below is the Function:

CREATE FUNCTION [dbo].[fnCustomDate]
(
    @DateFormat AS DATETIME
)
RETURNS VARCHAR (MAX)
AS
    BEGIN
        RETURN  DATENAME(DW,@DateFormat) + ' ' +
                DATENAME(D,@DateFormat) +
        CASE
            WHEN DAY(@DateFormat) IN (1, 21, 31) THEN 'st'
            WHEN DAY(@DateFormat) IN (2, 22) THEN 'nd'
            WHEN DAY(@DateFormat) IN (3, 23) THEN 'rd'
            ELSE 'th'
        END + ' ' +
                DATENAME(M,@DateFormat) + ' ' +
                DATENAME(YY,@DateFormat)    
    END
GO

Trying to execute it on a table for date column:

Select [dbo].[fnCustomDate](column name)
from [dbo].[tablename]

标签: sql-serverfunction

解决方案


“找不到列“dbo”或用户定义的函数或聚合“dbo.fnCustomDate”,或者名称不明确。”

未找到该函数时返回此错误。简单的检查事项:

您是否连接到正确的数据库?

函数拼写是否正确?

架构 dbo 是否存在?

我的函数在 dbo 模式中吗?

注意:该函数没有任何错误,或者您在提供的示例中如何调用它。


推荐阅读