2017-08-02 74 views
0

我有这个表:LEFT JOIN无法绑定

WS | Cat | Prod | CS | Dis| UserWS | MarA | ModA | MarU | BCIU 

我要加入他们为了得到即使有些是空的所有行的关系,我想这一点:

Select * 
FROM WS 
Left join MarU on MarU.Code=WS.used_brand 
Left join Prod p on p.MarA=Cat.OID 
Left join CS on WS.CS =CS.OID 
Left join Prod pp on WS.product_code=pp.Code 
Left join MarA on WS.customer_car_brand=MarA.Code 
Left join ModA on WS.customer_car_model=ModA.Code 
Left join CS c on c.UserWS=UserWS.Oid 
Left join CS css on css.Dis=Dis.OID 
Left join BCIU on BCIU.Code=WS.used_bci 

当我运行它时,出现此错误:

[Err] 42000 - [SQL Server]The multi-part identifier "Cat.OID" could not be bound. 42000 - [SQL Server]The multi-part identifier "UserWS.Oid" could not be bound. 42000 - [SQL Server]The multi-part identifier "Dis.OID" could not be bound. 42000 - [SQL Server]The multi-part identifier "Cat.Name" could not be bound. 42000 - [SQL Server]The multi-part identifier "Prod.Name" could not be bound. 42000 - [SQL Server]The multi-part identifier "Dis.Nombre" could not be bound. 42000 - [SQL Server]The multi-part identifier "UserWS.Nombre" could not be bound. 42000 - [SQL Server]The multi-part identifier "Cat.Segmento" could not be bound.

我失踪了什么?

+1

,你有没有在'JOIN'包括'Cat'任何地方事实上,我会说。 –

回答

2

您的错误信息实际上是多个错误。我依次处理它们。

见线开始-->

[Err] 
42000 - [SQL Server]The multi-part identifier "Cat.OID" could not be bound. 
--> Your SQL doesn't mention JOIN Cat table anywhere 

42000 - [SQL Server]The multi-part identifier "UserWS.Oid" could not be bound. 
--> Your SQL doesn't mention JOIN UserWS table anywhere 

42000 - [SQL Server]The multi-part identifier "Dis.OID" could not be bound. 
--> Your SQL doesn't mention JOIN Dis table anywhere 

42000 - [SQL Server]The multi-part identifier "Cat.Name" could not be bound. 
--> Your SQL doesn't mention JOIN Cat table anywhere 

42000 - [SQL Server]The multi-part identifier "Prod.Name" could not be bound. 
--> Your SQL doesn't call the Prod table "Prod", it joins it twice and aliases it as "p" and "pp". refer to p.Name or pp.Name, not Prod.Name 

42000 - [SQL Server]The multi-part identifier "Dis.Nombre" could not be bound. 
--> Your SQL doesn't mention JOIN Dis table anywhere 

42000 - [SQL Server]The multi-part identifier "UserWS.Nombre" could not be bound. 
--> Your SQL doesn't mention JOIN UserWS table anywhere 

42000 - [SQL Server]The multi-part identifier "Cat.Segmento" could not be bound. 
--> Your SQL doesn't mention JOIN Cat table anywhere 
1
Left join Prod p on p.MarA=Cat.OID 

上述语句中的Cat必须是Table或Table别名,但是在您的语句中没有称为Cat的表和别名。

之前加上LEFT JOIN CAT on [ForeignKey]=CAT.[PrimaryKey]

2

首先,简化查询,隔离错误。你会得到同样的错误:

SELECT * 
FROM WS Left join 
    MarU 
    on MarU.Code = WS.used_brand Left join 
    Prod p 
    on p.MarA = Cat.OID 

由于错误提示,Cat是不确定的。这不是前向参考问题,因为FROM子句中没有定义Cat。据推测,你只是忽略了相关的表格/视图。