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.
| 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... |
 |
|
|
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 statementEm |
 |
|
|
bjoerns
Posting Yak Master
154 Posts |
Posted - 2008-10-08 : 08:04:54
|
Could be something likeUPDATE t1SET t1.Email = t2.EmailFROM db1.dbo.table t1INNER JOIN db2.dbo.table t2ON t1.[Name] = t2.[Name] Is the Name unique or even primary key? |
 |
|
|
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. |
 |
|
|
nasu
Yak Posting Veteran
50 Posts |
Posted - 2008-10-09 : 02:29:03
|
| I tried the bjoerns way and it worked. Thanks! |
 |
|
|
|
|
|