Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 how to update table with date from another table ?

Author  Topic 

jylland
Starting Member

27 Posts

Posted - 2013-12-09 : 16:38:20
can anybody help me ?

I have two tables (tableA) and (TableB) in the same database

I plan a scheduled task every monday, it will take data from tableA and update TableB with them.

there are only 3 id's in every table, and the id rows in both tables is 1, 2 and 3.

TableA

id name
1 kay
2 bo
3 john

NeXT monday

the scheduled most update TableB with the data from TableA

so TableB after the scheduled executed look like this

id name
1 kay
2 bo
3 john

In the week after tableA will be updated with 3 new names, and the scheduled will NeXT monday again update TableB with this 3 names.

So there are always only 3 names. and every monday the scheduled will run.

How can I make a sql statement to update tableB with the data from tableA ??

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2013-12-09 : 18:47:42
[code]
update b
set name = a.name
from tablea a inner join tableb b on a.id = b.id
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

jylland
Starting Member

27 Posts

Posted - 2013-12-10 : 12:47:53
great
Go to Top of Page
   

- Advertisement -