?
Solved

update table with value from another table

Posted on 2014-03-18
2
Medium Priority
?
155 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
[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 Comments
 
LVL 40

Accepted Solution

by:
lcohan earned 1000 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 1000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Suggested Courses

771 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