Sql - 无法绑定多部分标识符


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'

我不断收到一个错误

多部分标识符页0。无法绑定主联系人。

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

谢谢!

您需要进行显式连接。当前使用的是旧的联接语法。考虑重构:

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'
您可以通过

更改表中表的顺序来使查询工作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的解决方案是编写查询的正确方法。

相关内容

  • 没有找到相关文章

最新更新