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
 Move Column of Data to another Table with a Join

Author  Topic 

StacyOW
Yak Posting Veteran

93 Posts

Posted - 2013-10-12 : 01:24:20
I have two tables. They both have an identity field to join them together. One of the tables has a column of data that I want to put in the other table. I need to make sure the data is brought over using the join so it updates that column for the right record.

I am struggling with this. Should I use a update or an insert? I'm leaning toward update but I can't figure out how with the join.

Any help would be much appreciated.

This is what I have tried so far:
Update grpcon.GroupID = groups.GroupID
from grpcon Inner Join groups
on grpcon.GroupNum=groups.GroupNum

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-10-12 : 03:59:16
[code]
Update g
SET g.GroupID = gp.GroupID
from grpcon g
Inner Join groups gp
on g.GroupNum=gp.GroupNum
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -