Solved

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

Posted on 2013-06-21
4
257 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 65

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 65

Expert Comment

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

Featured Post

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

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.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

710 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