Update a column of one table from other | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Update a column of one table from other

I have two tables and i need to update all the user name from NewUsers table to Employee table. Each Id in Employee column will have a new user name for the corresponding ID in NewUsers Table Example tables Table Employee ID UserName PWD subscription
1Jas123—-
2Kal765—-
3Taf123—-
Table NewUsers ID UserName
1Jas-Ani123
2Kal-Rai
3Jasper
Hence the desired result will be ID UserName PWD subscription
1Jas-Ani123 —- —–
2Kal-Rai —- —–
3Jasper —- —– Is there any way i can update the records of the Employee table with a query.
Currently i am using cursors to update the records.But there is a huge record set it takes time Ps provide me some idea on this

update e
set e.UserName = nu.UserName
from employee e
join newUsers nu on nu.id = e.id
where e.UserName <> nu.UserName

Thanks this was so simple i was not thining in the direction <img src=’/community/emoticons/emotion-6.gif’ alt=’:(‘ /><br />
I have a similar query which I have freshly posted. What if I have to update all records for iD 2 with that of id 1 in the same table i.e., id should appear as 2 but remaining values should be that of id.
This is a bit urgent and would appreciate a quick help.
Thanks,
SK. Thanks, StarWarsBigBang
Do Ids 1 and 2 have same number of rows? Madhivanan Failing to plan is Planning to fail
Thanks for the response madhivanan. Ids 1 and 2 may or may not have the same no. of rows. Please let me know of a solution.
Thanks, StarWarsBigBang
Then give us some sample data and the result you want Madhivanan Failing to plan is Planning to fail
]]>