Solved

update table with value from another table

Posted on 2014-03-18
2
150 Views
Last Modified: 2014-03-18
I have a column in Table1 called Age.  For every equivalent ID that I have in Table2 that has I would like to copy that value into a column called AgeReg

I would like to update Table2.AgeReg with Table1.Age where Table1.ID = Table2.ID

How can I write the SQL statement properly?
0
Comment
Question by:al4629740
2 Comments
 
LVL 39

Accepted Solution

by:
lcohan earned 250 total points
ID: 39937894
update Table2 set AgeReg = Table1.Age
from Table1
where Table1.ID = Table2.ID
0
 
LVL 40

Assisted Solution

by:Kyle Abrahams
Kyle Abrahams earned 250 total points
ID: 39937899
You can do this with a join as well:

update t2
set t2.AgeReg = t.age
from table2 t2
join table1 t1  on t2.Id = t1.ID
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
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.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

790 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