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
 General SQL Server Forums
 New to SQL Server Programming
 Row by Row update

Author  Topic 

Teachme
Starting Member

45 Posts

Posted - 2007-08-22 : 16:11:07
i have 2 tables t1(id1, id2) and t2(id).
t1 data:
100 101
200 101
300 101

t2 data:
100
200
400

I need to update t2(IDs) to id2 of t1 based on id1 of t1 meaning t2 would become 101,101, 400 (in other words update (t2.id) to (t1.id2) wherever t1.id1 = t2.id). These are jus a few rows the actual data is much more so i'm not sure if i use a while loop how do i do it or would a cursor be a better option and how. Thanks for any kind of help.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-08-22 : 16:14:03
update t2
set t2.id = t1.id2
from t2
inner join t1 on t1.id1 = t2.id



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

Teachme
Starting Member

45 Posts

Posted - 2007-08-22 : 16:20:16
i was thinking way over on that one. thanks
Go to Top of Page
   

- Advertisement -