Solved

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

Posted on 2013-06-21
4
258 Views
Last Modified: 2013-06-21
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
Comment
Question by:RBS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 15

Expert Comment

by:gplana
ID: 39266501
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
 
LVL 66

Accepted Solution

by:
Jim Horn earned 500 total points
ID: 39266507
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
 

Author Closing Comment

by:RBS
ID: 39266517
Perfect, thanks!

RBS
0
 
LVL 66

Expert Comment

by:Jim Horn
ID: 39266548
Thanks for the grade.  Good luck with your project.  -Jim
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question