Solved

SQL Statment

Posted on 2010-11-19
5
439 Views
Last Modified: 2012-05-10
What is wrong with this code? i get this error

 System.Data.SqlClient.SqlException: The multi-part identifier "Employee.ID" could not be bound.
SELECT        Employees.title, Employees.firstName, Employees.lastName, Addresses.Line1, Addresses.Line2, Addresses.Line3, Addresses.City, Addresses.Postcode

FROM            Employees INNER JOIN

                         Addresses ON Employees.addressId = Addresses.ID

WHERE        (Employees.ID NOT IN

                             (SELECT        EmployeeID

                               FROM            ExpenceForms))

Open in new window

0
Comment
Question by:aaron-macleod
5 Comments
 
LVL 28

Accepted Solution

by:
sammySeltzer earned 500 total points
Comment Utility
I think it should be something like this:

SELECT Employees.title, Employees.firstName, Employees.lastName, Addresses.Line1, 
Addresses.Line2, Addresses.Line3, Addresses.City, Addresses.Postcode
FROM   Employees INNER JOIN
                         Addresses ON Employees.addressId = Addresses.ID
WHERE  Employees.ID NOT IN (SELECT ExpenceForms.EmployeeID
                               FROM ExpenceForms)

Open in new window

0
 
LVL 33

Expert Comment

by:paulmacd
Comment Utility
You have both Employee.ID and EmployeeID.  Are they both present?
0
 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
your exception has Employee while your query as EmployeeS. do you have a typo?
0
 
LVL 41

Expert Comment

by:ralmada
Comment Utility
>> The multi-part identifier "Employee.ID" could not be bound.<<
That query doesn't seem to be producing that error. The error is caused because you are trying to use a column named ID from a table called (or aliased) "Employee" (without "s" at the end) . I don't see anywhere in the above query the "Employee.ID" expression.

Anyway, check your column and alias to ensure that they match with your current tables definition.

Also, another way of doing this query is
SELECT  Employees.title, 

	Employees.firstName, 

	Employees.lastName, 

	Addresses.Line1, 

	Addresses.Line2, 

	Addresses.Line3, 

	Addresses.City, 

	Addresses.Postcode

FROM    Employees 

INNER JOIN Addresses ON Employees.addressId = Addresses.ID

INNER JOIN ExpenceForms ON Employees.ID <> ExpenceForms.EmployeeID

Open in new window

0
 
LVL 41

Expert Comment

by:ralmada
Comment Utility
crap, too late
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Join & Write a Comment

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how the fundamental information of how to create a table.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now