Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Multi part identifier could not be bound

Author  Topic 

CoffeeAddict
Yak Posting Veteran

94 Posts

Posted - 2010-04-22 : 14:50:16
God I hate SQL, what now. What quirky gotcha or special thing did I miss for this inner SQL statement not able to see outside?

select * from order o
where city = 'Baltimore'
and NOT EXISTS (Select * from Cash c where c.id = o.id)

Error: Multi part identifier o.id could not be bound

Ok, an inner select cannot see outside itself due to table scope or whatever...which I think is just stupid but you know...I can't figure out then how to twist this around to make it work. How the hell can I get this to be "happy".

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-04-22 : 14:55:01
Your query works fine for me. Are you sure you are showing us the actual query? Are you using SQL Server or some other dbms?

Here's my test:

create table #order (id int, city varchar(50))
create table #cash (id int)

insert into #order values(1, 'San Diego')
insert into #order values(2, 'Baltimore')

insert into #cash values(1)

select * from #order o
where city = 'Baltimore'
and NOT EXISTS (Select * from #cash c where c.id = o.id)

drop table #order, #cash


Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

CoffeeAddict
Yak Posting Veteran

94 Posts

Posted - 2010-04-22 : 15:21:03
How weird. I opened a new query window (because I was also getting an error saying orders table did not exist and I know for a fact it does) and it's working fine.

Thanks anyway.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-04-22 : 15:32:58
It sounds like you were in the wrong database then.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

CoffeeAddict
Yak Posting Veteran

94 Posts

Posted - 2010-04-24 : 23:05:18
No I checked that several times. It was the right database. For some reason I see this a lot. SQL Server shows squigglies under certain parts of my syntax like tables, field names, etc. when there in fact is no problem. It's like SQL Server has cashed some old compiled errors and still showing squigglies for stuff that is no longer a syntax problem (after you've fixed it..it still shows squigglies for some reason like something is cached in SQL Server Query Analyzer).
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-04-25 : 00:47:18
Is your SSMS client patched to the latest?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -