SQL 查询错误:多部分标识符...无法绑定

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7841404/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 12:33:27  来源:igfitidea点击:

SQL Query error: The multi-part identifier ... could not be bound

sqlsql-server

提问by Chris Hull

I'm sure this is obvious but I can't seem to figure out why I'm getting the error.

我确定这很明显,但我似乎无法弄清楚为什么我会收到错误。

"Msg 4104, Level 16, State 1, Line 1 The multi-part identifier "dbo.ProductCode.ProductCode" could not be bound."

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

I'm joining many tables base on the "Name" column in each table, but in this case I need to link ProductCodeReference.ProductCode to ProductCode.ProductCode and pull ProductCodeReference.ProductName based on ProductCode.Name

我根据每个表中的“名称”列加入许多表,但在这种情况下,我需要将 ProductCodeReference.ProductCode 链接到 ProductCode.ProductCode 并根据 ProductCode.Name 拉取 ProductCodeReference.ProductName

SELECT 
dbo.Servers.Name, 
dbo.ProductCodeReference.ProductName,
dbo.Enclosure.Model, 
dbo.OperatingSystem.FullOS, dbo.OperatingSystem.osbit,
dbo.OperatingSystem.ServicePack, dbo.OperatingSystem.Version,
dbo.Processor.Processors, dbo.Processor.CoreCount,
dbo.Memory.capacity,
dbo.MarcLevel.marcLevel
FROM dbo.Servers

INNER JOIN dbo.ProductCodeReference
ON dbo.ProductCode.ProductCode=dbo.ProductCodeReference.ProductCode

INNER JOIN dbo.Enclosure
ON dbo.Servers.Name=dbo.Enclosure.Name

INNER JOIN dbo.OperatingSystem
ON dbo.Servers.Name=dbo.OperatingSystem.Name

INNER JOIN dbo.Processor
ON dbo.Servers.Name=dbo.Processor.Name

INNER JOIN dbo.Memory
ON dbo.Servers.Name=dbo.Memory.name

INNER JOIN dbo.MarcLevel
ON dbo.Servers.Name=dbo.MarcLevel.name

ORDER BY dbo.Servers.Name

Hopefully that makes sense. Thanks!

希望这是有道理的。谢谢!

回答by James Johnson

The issue is with the line shown below, because there is no table called ProductCodein the query:

问题在于下面显示的行,因为ProductCode查询中没有调用表:

dbo.ProductCode.ProductCode

It looks like you forgot to include the ProductCodetable in your query.

看起来您忘记ProductCode在查询中包含该表。

FROM dbo.Servers  

INNER JOIN dbo.ProductCode
ON .... = ....  

INNER JOIN dbo.ProductCodeReference  
ON dbo.ProductCode.ProductCode=dbo.ProductCodeReference.ProductCode 

回答by Joe Stefanelli

There's no reference to a dbo.ProductCodetable anywhere in your query except this one line:

dbo.ProductCode除了这一行之外,在您的查询中的任何地方都没有对表的引用:

ON dbo.ProductCode.ProductCode=dbo.ProductCodeReference.ProductCode

That table needs to be specified by a JOIN somewhere.

该表需要由某处的 JOIN 指定。