Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Combine two tables

Author  Topic 

newbb
Starting Member

4 Posts

Posted - 2011-10-20 : 11:19:42
Hello I have two databases, db1 and db2. Both of these have similiar tables called information. Both tables have similiar amount of columns
but partially different data, so there is also some duplicate values in these tables but i know I can separate those values by column called nro.

So what am I doing wrong with that query below?

I only get this error message:

Msg 4104, Level 16, State 1, Line 7
The multi-part identifier "db1.dbo.information.nro" could not be bound.


My query

insert into db1.dbo.information
select *
from db2.dbo.information
where not exists (
select *
from db2.dbo.information
where db2.dbo.information.nro = db1.dbo.information.nro)

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-10-20 : 11:27:05
[code]
insert into db1.dbo.information
select *
from db2.dbo.information
where not exists
(
select *
from db1.dbo.information
where db1.dbo.information.nro = db2.dbo.information.nro
)
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-21 : 00:37:52
better to use short aliases so that you dont have to repeat 3 part name everywhere

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -