Solved

update table with value from another table

Posted on 2014-03-18
2
147 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 39

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

762 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now