Link to home
Start Free TrialLog in
Avatar of aaron-macleod
aaron-macleod

asked on

SQL Statment

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

ASKER CERTIFIED SOLUTION
Avatar of sammySeltzer
sammySeltzer
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Paul MacDonald
You have both Employee.ID and EmployeeID.  Are they both present?
your exception has Employee while your query as EmployeeS. do you have a typo?
>> 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

crap, too late