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
 Re: Append a table

Author  Topic 

dr223
Constraint Violating Yak Guru

444 Posts

Posted - 2010-05-27 : 08:12:21
Hi,

I have two tables tblA and tblB.
tblA has 4 fields
Name
Address1
Address2
Town (this field I have just created and it is NULL for all records)

tblB has 4 fields
Name
Address1
Address2
Town

I want to write a query where if the Name in tblA is the same as Name in tblB. Town field is populated with respective data from tblB.

Thanks

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-05-27 : 08:30:44
If more than one person are having the same name then this update is dangerous - you know?
update a
set Town=b.town
from tableA as a
join tableB as b on a.name=b.name


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

dr223
Constraint Violating Yak Guru

444 Posts

Posted - 2010-05-27 : 11:59:03
Thanks worked fine
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-05-27 : 12:58:20
welcome


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -