1
select distinct 
   page0.MatterType, 
   page0.Name, 
   page0.MatterNo, 
   page0.security, 
   page0.serial,      
   page6.TribCaseNo, 
   contact0.Name as Cname
from 
   page0, page6, page14
left join 
   contact0 on page0.PrimaryContact = contact0.linkserial
where 
  page0.serial = page6.CaseSerial 
AND page0.serial = page14.CaseSerial 
AND (page14.staffmember = '100001^24' and page14.status != 'Inactive') 
AND page0.status != 'Closed'

我不断收到一个错误

无法绑定多部分标识符 page0.PrimaryContact。

我检查了语法和拼写,似乎都是正确的。

谢谢!

4

2 回答 2

6

您需要进行显式连接。目前您正在使用旧的连接语法。考虑重构:

select P0.*, P6.TribCaseNo, C0.Name as Cname
FROM        page0 AS P0
INNER JOIN  page6 AS P6 on P0.serial = P6.CaseSerial 
INNER JOIN  page14 AS P14 ON P0.serial = P14.CaseSerial
LEFT JOIN   contact0 AS C0 on P0.PrimaryContact = C0.linkserial

WHERE (P14.staffmember = '100001^24' AND P14.status != 'Inactive') 
AND   P0.status != 'Closed'
于 2012-02-27T17:22:52.193 回答
1

您可以通过更改以下表格的顺序来使您的查询工作FROM

select distinct   
page0.MatterType,   
page0.Name,   
page0.MatterNo,   
page0.security,   
page0.serial,        
page6.TribCaseNo,   
contact0.Name as Cname  
from   
 page6, page14, page0 --NOTE: page0 is now  closest to join!!!
left join   
contact0 on page0.PrimaryContact = contact0.linkserial  
where   
page0.serial = page6.CaseSerial   
AND page0.serial = page14.CaseSerial   
AND (page14.staffmember = '100001^24' and page14.status != 'Inactive')   
AND page0.status != 'Closed'  

更新
一般来说,我强烈建议您不要混合新旧语法(就像这里所做的那样),p.campbell的解决方案是编写查询的正确方法。

于 2012-02-27T18:02:54.050 回答