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 2000 Forums
 SQL Server Development (2000)
 updating table field based on matching values on..

Author  Topic 

AbuAnas
Starting Member

4 Posts

Posted - 2004-10-24 : 06:54:05
Hi. Assuming that I have the following schema
t1
(id, filed)

t2
(id, filed)

t3
(id, ref)

I want to update ALL the values in t3.ref to be equal t1.id whenever t3.ref=t2.id and t1.field = t2.field
In other words I would like to update all refs in t3 to be equal to id's in t1 insted of id's of t2 whenever the filed cloumns match in t1 and t2

What is the correct SQL statment to be used (or tool if any). I am using MS SQL


Thanx

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-10-24 : 13:09:20
I want to update ALL the values in t3.ref to be equal t1.id whenever t3.ref=t2.id and t1.field = t2.field
will this work for you?

update t3
set ref = t1.id
from table3 t3
inner join table2 t2 on t3.ref = t2.id
inner join table1 t1 on t1.field = t2.field

Go with the flow & have fun! Else fight the flow
Go to Top of Page
   

- Advertisement -