Solved

Insert into a different database using where clause on a column

Posted on 2010-08-16
5
452 Views
Last Modified: 2012-08-14
I am having trouble with the last item..the where clause in my insert statement.
I keep getting an error of.. "The multi-part  identifier ... could not be bound."
Any ideas greatly appreciated!

INSERT INTO [targetdatabase].[dbo].[mytable]( field1, field2,field3)
SELECT field1, field2, field3
FROM [sourcedatabase].[dbo].[mytable]
where [targetdatabase].[dbo].[mytable].myfield not in(select myfield from sourcedatabase)
0
Comment
Question by:H-SC
[X]
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
  • 2
  • 2
5 Comments
 
LVL 7

Expert Comment

by:lundnak
ID: 33447287
This error is generally a problem with the syntax of your select statement.
Do you have table aliases defined in the FROM clause?  I double check the table aliases against the fields in the SELECT and WHERE clauses.
0
 
LVL 7

Expert Comment

by:lundnak
ID: 33447321
For Example:

Select tbl1.fld1, tbl2.fld1
from table1 as tbl1
join table2 as tbl2 on tbl2.id = tbl1.id

If the fields in the SELECT clause do not have a unique name and the table alias assignment is missing, then you will get this error.
You will also get the error if you misspell a table alias.  (i.e. tbbl2.fld1 instead of tbl2.fld1)

Make sure you check the GROUP BY and ORDER BY clauses also.
0
 
LVL 1

Author Comment

by:H-SC
ID: 33447340
lundnak,

I am not using aliases
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 33447516
please try
INSERT INTO [targetdatabase].[dbo].[mytable]( field1, field2,field3)
SELECT field1, field2, field3
FROM [sourcedatabase].[dbo].[mytable] t
where not exists ( select null from sourcedatabase s where t.myfield = s.myfield )

Open in new window

0
 
LVL 1

Author Comment

by:H-SC
ID: 33448280
angelIII,

Perfect!

many thank you's
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
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 ?
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

729 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