【问题标题】:TSQL Function The multi-part identifier "" could not be boundTSQL 函数无法绑定多部分标识符“”
【发布时间】:2014-05-06 20:36:08
【问题描述】:

我有一个函数,它是一个简单的 case 语句,但是当我尝试执行这个函数时,我得到了错误:

消息 4104,第 16 级,状态 1,第 1 行 无法绑定多部分标识符“EXTRAS.FindCustomerfromCostCentre”。

我的函数很简单...

Alter FUNCTION [EXTRAS].[FindCustomerfromCostCentre] 

(
    @CostCentre Varchar
)
RETURNS int
AS
BEGIN

return  
case 
    when SUBSTRING(@CostCentre,3,3) = '401' Then '7010'
    when SUBSTRING(@CostCentre,3,3) = '402' Then '7020'
    when SUBSTRING(@CostCentre,3,3) = '403' Then '7030'
    when SUBSTRING(@CostCentre,3,3) = '407' Then '7070'
    when SUBSTRING(@CostCentre,3,3) = '409' Then '7090'
    when SUBSTRING(@CostCentre,3,3) = '414' Then '7140'
    when SUBSTRING(@CostCentre,3,3) = '416' Then '7160'
    Else '0'
end 
END

当我执行时,我是这样调用的

SELECT  [EXTRAS].[FindCustomerfromCostCentre] CostCentre_Code

FROM dbo.COSTCENTRE

Where STATUS = 'Active'

关于我为什么会收到此错误的任何提示?

【问题讨论】:

    标签: tsql


    【解决方案1】:

    你需要在参数两边加上括号

    SELECT  [EXTRAS].[FindCustomerfromCostCentre](CostCentre_Code)
    
    FROM dbo.COSTCENTRE
    
    Where STATUS = 'Active'
    

    您还需要在函数的声明中指定参数的长度。

    (
        @CostCentre Varchar
    )
    

    不这样做会给你一个varchar(1)

    (
        @CostCentre Varchar(1)
    )
    

    【讨论】:

      猜你喜欢
      • 2013-08-17
      • 2011-11-10
      • 2010-11-02
      • 2023-03-21
      相关资源
      最近更新 更多