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 |
|
scottdg
Starting Member
20 Posts |
Posted - 2012-09-10 : 15:03:05
|
| I created a column in a table and now I want to update it with concatenated data from an existing column in the same table and a column from another table:table AFull_Name_And Company (New Column)Full_NameTable BCompanyGiven the 2 tables above how do I update Full_Name_And Company with a concatenation of Full_Name + Company? |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-09-10 : 15:05:00
|
| how are two tables related? is there a common field?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
scottdg
Starting Member
20 Posts |
Posted - 2012-09-10 : 15:22:35
|
| Yes sorry...they have a common ID#table AFull_Name_And Company (New Column)Full_NameCustomer_IDTable BCompanyCustomer_ID |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-09-10 : 15:32:05
|
| [code]UPDATE aSET a.Full_Name_And Company = COALESCE(a.Full_Name,'') + COALESCE(b.Company ,'')FROM TableA aINNER JOIN TableB bON b.Customer_ID = a.Customer_ID[/code]if columns are NOT NULL you can avoid the COALESCE()------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
scottdg
Starting Member
20 Posts |
Posted - 2012-09-10 : 15:46:03
|
| Hmm...looks very similar to what I tried without the COALESCE() which I will need for Company_Name. I will try it again.Thanks. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-09-10 : 15:52:39
|
| welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|