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
 Adding column to another table

Author  Topic 

JJ297
Aged Yak Warrior

940 Posts

Posted - 2010-05-13 : 15:43:15
I have a table called WeeklyDiaries that has the field HUN in it.

I want to add the Hun field to the Alldiaries field. I created the field already now ready to add the data. I can join both tables on weeklyid. How would I write this?

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-05-13 : 15:47:07
Some sample data will help...but looks like this.
UPDATE a
SET a.Hun = b.Hun
from Alldiaries a
inner join WeeklyDiaries b on a.weeklyid = b.weeklyid
Go to Top of Page

JJ297
Aged Yak Warrior

940 Posts

Posted - 2010-05-13 : 16:03:42
Thanks!

Alldiaries data

WeeklyID         drycde         drydat          HUN
0 MR NULL NULL
1 MR NULL NULL
2 D1 NULL NULL
3 B9 9/18/2006 NULL
4 MR NULL NULL
5 B9 3/28/2006 NULL



WeeklyDiaries Table data

WeeklyID         hun                  
0 07611
1 32122
2 40628
3 41755 I
Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-05-13 : 16:05:43
The query I gave should work for you, no?
Go to Top of Page

JJ297
Aged Yak Warrior

940 Posts

Posted - 2010-05-13 : 16:06:42
Yes it did thank you!!!
Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-05-13 : 16:07:41
Np. You're welcome.
Go to Top of Page
   

- Advertisement -