Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

SQL Statment

Posted on 2010-11-19
5
448 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
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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SSRS Deployment problem 5 66
where to find DTS instalation package for sql 2014 64 bit 3 11
Are triggers slow? 7 12
how to restore or keep sql2000  backups useful... 2 14
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

838 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