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 2005 Forums
 Transact-SQL (2005)
 For all users copy

Author  Topic 

nasu
Yak Posting Veteran

50 Posts

Posted - 2008-10-08 : 07:47:50
I have a USERS table in a database. Each user has a NAME and an EMAIL field. They are all empty. However, I have all users' e-mail adresses in another database/table where each user has the corresponding fields.

Now I want to copy each user's e-mail adress from that other database/table. I do not want to remove or add any records in the first database, only update each user's e-mail address.

This is probably easy but I am not an experienced SQL user. Can anyone help me?

nasu
Yak Posting Veteran

50 Posts

Posted - 2008-10-08 : 07:49:15
Sorry about the title of this topic. It was a mistake...
Go to Top of Page

elancaster
A very urgent SQL Yakette

1208 Posts

Posted - 2008-10-08 : 08:02:47
how are they related? do they share a common id for example? if you show us the table definitions we can help you write the update statement

Em
Go to Top of Page

bjoerns
Posting Yak Master

154 Posts

Posted - 2008-10-08 : 08:04:54
Could be something like
UPDATE t1
SET t1.Email = t2.Email
FROM db1.dbo.table t1
INNER JOIN db2.dbo.table t2
ON t1.[Name] = t2.[Name]

Is the Name unique or even primary key?
Go to Top of Page

nasu
Yak Posting Veteran

50 Posts

Posted - 2008-10-08 : 08:18:45
The users do NOT share a common USER_ID field. The NAME field is unique. But I see there are less records in the "other" database/table, i.e. we may not find some users but that is OK for now.
Go to Top of Page

nasu
Yak Posting Veteran

50 Posts

Posted - 2008-10-09 : 02:29:03
I tried the bjoerns way and it worked. Thanks!
Go to Top of Page
   

- Advertisement -