SQL 错误 - 无法绑定多部分标识符“CF.OBJ”

Posted

技术标签:

【中文标题】SQL 错误 - 无法绑定多部分标识符“CF.OBJ”【英文标题】:SQL Error - The multi-part identifier "CF.OBJ" could not be bound 【发布时间】:2017-12-04 19:10:19 【问题描述】:

我收到关于子查询连接的多部分标识符的错误。请帮忙。以下是我写的代码

SELECT CORE.BC_NUMBER AS BC,SEG.BC_NUMBER AS SEGBC,XREF.BC_NUMBER AS XREFBC,CF.OBJ
-- Table CORE
From CORE

-- join seg and core
LEFT JOIN SEG
ON CORE.BC_NUMBER= SEG.BC_NUMBER

-- Join XREF to go from BCNbr to GBC
LEFT JOIN 
XREF
ON XREF.BUNL=SEG.BC_NUMBER;

-- GEN JOIN GBC
LEFT JOIN

(SELect JID,P,Obj, JT
From Gen) AS CF

ON CF.Obj=XREF.BC_NUMBER

;

sqlfiddle.com/#!6/29f643/15

【问题讨论】:

在最后一个左连接处将 From Gen AS CF) ON.... 更改为 From Gen) AS CF ON .... 您可能还想在最后一个 LEFT JOIN 中拼出单词 SELECT 【参考方案1】:

看起来你在子查询中有别名;尝试以下方法:

SELECT CORE.BC_NUMBER AS BC,SEG.BC_NUMBER AS SEGBC,XREF.BC_NUMBER AS 

XREFBC,CF.OBJ
-- Table CORE
From CORE

-- join seg and core
LEFT JOIN SEG
ON CORE.BC_NUMBER= SEG.BC_NUMBER

-- Join XREF to go from BCNbr to GBC
LEFT JOIN XREF
ON XREF.BUNL=SEG.BC_NUMBER

-- GEN JOIN GBC
LEFT JOIN (   
    SELECT JID,P,Obj, JT
    From Gen
    where JT=28 and P=1
)CF
ON CF.Obj=XREF.BC_NUMBER
;

【讨论】:

在第二个 LEFT JOIN 上删除 ; 分号。这将阻止第三个LEFT JOIN 被 SQL 看到。【参考方案2】:

因为您在括号内使用了 CF 别名并在括号外使用了引用。这里还没有创建CF别名,请在括号外使用CF别名作为参考

SELECT CORE.BC_NUMBER AS BC,SEG.BC_NUMBER AS SEGBC,XREF.BC_NUMBER AS XREFBC,CF.OBJ
-- Table CORE
From CORE

-- join seg and core
LEFT JOIN SEG
ON CORE.BC_NUMBER= SEG.BC_NUMBER

-- Join XREF to go from BCNbr to GBC
LEFT JOIN 
XREF
ON XREF.BUNL=SEG.BC_NUMBER;

-- GEN JOIN GBC
LEFT JOIN

(SEL JID,P,Obj, JT
From Gen 
) AS CF
ON CF.Obj=XREF.BC_NUMBER
;

【讨论】:

以上是关于SQL 错误 - 无法绑定多部分标识符“CF.OBJ”的主要内容,如果未能解决你的问题,请参考以下文章

SQL 错误 - 无法绑定多部分标识符“CF.OBJ”

协助 SQL 查询 - 无法绑定多部分标识符

SQL Server 2008 - 返回连接条目和“无法绑定多部分标识符”错误的用户定义函数

无法在 SQL Server 2008 上绑定多部分标识符

无法绑定多部分标识符“p.ProductID”

Crystal Reports中的“多部分标识符无法绑定”与SQL表达式/子查询