簡體   English   中英

odbc調用失敗[microsoft] [sql server本機客戶端11.0] [sql server]多部分標識符盤繞不綁定

[英]odbc call failed [microsoft] [sql server native client 11.0] [sql server] the multipart identifier coild not be bound

我有兩個查詢,它們使用通過ODBC數據庫鏈接的表,兩個查詢都非常簡單並且可以單獨工作。

查詢1:

SELECT 
    People.First_name, People.Last_name, Awards.[Award Name], 
    Recipients.Affiliation, Recipients.Recipient_Award_Comments, 
    Recipients.Recipient_Date, People.PersonID 
FROM
    People 
INNER JOIN 
    (Awards 
INNER JOIN 
    Recipients ON Awards.AwardID = Recipients.AwardID) ON People.PersonID = Recipients.PersonID;

查詢2:

SELECT 
    Awards.[Award Name], People.First_name, People.Last_name, 
    Contenders.Contender_Date_Assigned, 
    Contenders.Award_Contender_Comments, People.PersonID
FROM 
    people, contenders, awards
WHERE 
    Awards.AwardID = Contenders.AwardID 
    AND People.PersonID = Contenders.PersonID;

我嘗試在這些查詢上使用左聯接(在access上工作正常,但是在將數據遷移到SQL Server上)我收到此錯誤:

odbc調用失敗[microsoft] [sql server native client 11.0] [sql server]不能綁定多部分標識符'Contenders.PersonID','Contenders.AwardID'和'Awards.AwardID'。

在進行內部聯接時,它工作正常,但這不是我想要的。

查詢r + c

SELECT 
    Query1.First_name, Query1.Last_name, Query1.[Award Name], 
    Query1.Affiliation, Query1.Recipient_Award_Comments, 
    Query1.Recipient_Date, Query2.First_name, Query2.Last_name, 
    Query2.[Award Name], Query2.Contender_Date_Assigned, 
    Query2.Award_Contender_Comments, Query1.PersonID
FROM
    Query1 
LEFT JOIN 
    Query2 ON Query1.PersonID = Query2.PersonID;

你可以做 :

with Query11 as
(
   <Query11 goes here>
), Query22 as
(
   <Query22 goes here>
)

select  q1.First_name, q1.Last_name, Query1.[Award Name], 
        q1.Affiliation, q1.Recipient_Award_Comments, 
        q1.Recipient_Date, q2.First_name, Query2.Last_name, 
        q2.[Award Name], q2.Contender_Date_Assigned, 
        q2.Award_Contender_Comments, q1.PersonID
from Query11 q1 left join
     Query22 q2
     on q2.PersonID = q1.PersonID; 

我將Query11重寫為:

SELECT p.First_name, p.Last_name, a.[Award Name], 
       r.Affiliation, r.Recipient_Award_Comments, 
       r.Recipient_Date, p.PersonID 
FROM People p INNER JOIN 
     Recipients r
     ON p.PersonID = r.PersonID INNER JOIN
     Awards a
     ON a.AwardID = r.AwardID;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM