aaron-macleod
asked on
SQL Statment
What is wrong with this code? i get this error
System.Data.SqlClient.SqlE xception: The multi-part identifier "Employee.ID" could not be bound.
System.Data.SqlClient.SqlE
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))
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
crap, too late