The multi part identifier could not be bound.

Can an expert take a look at line 4 below. I think my syntax is incorrect. Query analyzer is giving me the error message: The multi part identifier potion.ENTITY_ID could not be bound.




1.  SELECT ENTITY_ID INTO #Temp from prad p where p.ENTITY_ID NOT IN (SELECT ENTITY_ID from mctn)

2.  CREATE TABLE #Temp(ENTITY_ID varchar(64), NAME      varchar(64))
                   

3.  INSERT INTO #Temp (ENTITY_ID) SELECT p.ENTITY_ID from prad p where p.ENTITY_ID NOT IN (SELECT ENTITY_ID FROM MCTN)

4.  UPDATE #Temp SET #Temp.NAME = potion.NAME WHERE #Temp.ENTITY_ID = potion.ENTITY_ID)
LVL 2
brgdotnetcontractorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
4 is not correct.  Two tables are mentioned, #Temp and potion, but no JOIN clause to explain how the two are related.  Give this a whirl..

UPDATE #temp
SET #Temp.NAME = potion.NAME
FROM #temp
   JOIN potion ON #Temp.ENTITY_ID = potion.ENTITY_ID  -- assuming these are the related columns

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ryan ChongCommented:
for statement 4, you forgot to join the table potion in your update sql statement...

but in fact, you can combine all 4 queries to something like this:

SELECT p.ENTITY_ID, potion.NAME into #Temp
from prad p inner join potion on p.ENTITY_ID = potion.ENTITY_ID
where p.ENTITY_ID NOT IN (SELECT ENTITY_ID FROM MCTN)

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.