• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 187
  • Last Modified:

update table with value from another table

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
al4629740
Asked:
al4629740
2 Solutions
 
lcohanDatabase AnalystCommented:
update Table2 set AgeReg = Table1.Age
from Table1
where Table1.ID = Table2.ID
0
 
Kyle AbrahamsSenior .Net DeveloperCommented:
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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now