Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 260
  • Last Modified:

Copying values related to one column in one table to another with same values of second column

Hi:

I have a table aspnet_Users with columns UserId (uniqueidentifier) and UserName varchar(256).  

What I would like to do is copy all the UserName values from this table to my UserProfiles table that  also has also has UserId and UserName columns so that the UserName values match the UserId values in the new table - i.e.  username jsmith in record with UserId=xxyx in aspnet_Users is copied to the record in UserProfiles that has a UserId of xxyx

Any help greatly appreciated.

RBS
0
RBS
Asked:
RBS
  • 2
1 Solution
 
gplanaCommented:
You should made a join on the update sentence. Please see this link: http://stackoverflow.com/questions/1262786/mysql-update-query-based-on-select-query

Hope it helps. Regards.
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Something like ...

UPDATE UserProfiles
SET UserName = au.UserName
FROM aspnet_Users au
   JOIN UserProfiles up ON au.UserId = up.UserId

You'll also want to consider an INSERT of all rows that are in aspnet_Users but not in UserProfies, based on the UserId.

Hope this helps.
Jim
0
 
RBSAuthor Commented:
Perfect, thanks!

RBS
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Thanks for the grade.  Good luck with your project.  -Jim
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now