Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL Statment

Posted on 2010-11-19
5
Medium Priority
?
466 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 29

Accepted Solution

by:
sammySeltzer earned 2000 total points
ID: 34173971
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 34

Expert Comment

by:Paul MacDonald
ID: 34173985
You have both Employee.ID and EmployeeID.  Are they both present?
0
 
LVL 70

Expert Comment

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

Expert Comment

by:ralmada
ID: 34174058
>> 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
ID: 34174063
crap, too late
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

972 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