Sql - the multi-part identifier cannot be bound

badD0g01 picture badD0g01 · Feb 27, 2012 · Viewed 17.4k times · Source
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'

I keep getting an error that

the multi-part identifier page0.PrimaryContact could not be bound.

I've checked the syntax and the spelling and both seem to be correct.

Thanks!

Answer

p.campbell picture p.campbell · Feb 27, 2012

You'll need to make explicit joins. Currently you're using the old join syntax. Consider refactoring:

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'