Solved

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

Posted on 2013-06-21
4
254 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
  • 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

803 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