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
 General SQL Server Forums
 New to SQL Server Programming
 Merging data from two databases

Author  Topic 

thehandsomecode
Yak Posting Veteran

51 Posts

Posted - 2007-09-14 : 12:07:57
i have two databases one has
firstname, lastname
and the othere
firstname, lastname, emailaddress

how do i get to merge the data from emailaddress to the 1st datbase?

Melvin Felicien
IT Manager
DCG Properties Limited

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2007-09-14 : 12:22:10
USe UNION ALL STATEMENT
Go to Top of Page

thehandsomecode
Yak Posting Veteran

51 Posts

Posted - 2007-09-14 : 12:26:13
i am not that good with SQL can you guide me?

Melvin Felicien
IT Manager
DCG Properties Limited
Go to Top of Page

thehandsomecode
Yak Posting Veteran

51 Posts

Posted - 2007-09-14 : 12:27:45
i also need it to make the union or merge based on when the first name and lastname matched a record in the 2nd table

Melvin Felicien
IT Manager
DCG Properties Limited
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-09-14 : 12:29:11
insert into table1 (firstname, lastname)
select firstname, lastname from table2
where not exists (select * from table1 as t1 where t1.firstname = table2.firstname and t1.lastname = table2.lastname)



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

thehandsomecode
Yak Posting Veteran

51 Posts

Posted - 2007-09-14 : 13:19:05
Thank you. this seems to work to input new data but what i want is to append the data to an existing record.
okay here it is.
i have two identical databases. one contains emailaddresses and theother doesnt. i want to inset the email addresses next to the correct names.
Please help.

Melvin Felicien
IT Manager
DCG Properties Limited
Go to Top of Page

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2007-09-22 : 09:15:20
In that case , use an UPDATE statement. For example , update t1 set t1.field=t2.fields from table1 t1 inner join table2 t2 on t1.primaryKey=t2.foreignkey


Jack Vamvas
--------------------
Need an IT job ? http://www.ITjobfeed.com
Go to Top of Page
   

- Advertisement -