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)
 how to update a table with another table

Author  Topic 

liangtp@hotmail.com
Starting Member

27 Posts

Posted - 2008-09-10 : 05:48:07
Guys,

I have a tblA with the following fields:
IDNo, Name
1, NULL
2, Michael Phelps
3, NULL
4, Usain Bolt

I have another tblB with complete information:
IDNo, Name
1, Bill Gates
2, Michael Phelps
3, Ben Johnson
4, Usain Bolt.

Question: how do I write an SQL statement to update the NULL values in tblA with the values in tblB, using IDNo as the link?
Thanks.

sunil
Constraint Violating Yak Guru

282 Posts

Posted - 2008-09-10 : 05:52:30
Try,

Update tblA SET tblA.NAME=tblB.Name FROM tblA INNER JOIN tblB
ON tblA.IDNO=tblB.IDNO WHERE tblA.NAME IS NULL
Go to Top of Page

liangtp@hotmail.com
Starting Member

27 Posts

Posted - 2008-09-10 : 06:04:22
Thanks Sunil. It worked.
Cheers.
Go to Top of Page
   

- Advertisement -