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
RBSAsked:
Who is Participating?
 
Jim HornConnect With a Mentor Microsoft 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
 
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
 
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
All Courses

From novice to tech pro — start learning today.