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.
| Author |
Topic |
|
Mondeo
Constraint Violating Yak Guru
287 Posts |
Posted - 2007-10-05 : 05:02:34
|
| Hi,I want to loop through a table and update the value of field 1 with the value of field 2 in the same row. How can I do that?Thanks |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-10-05 : 05:05:04
|
| [code]Update Tableset Field1 = Field2Where <some_condition>[/code]Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
Mondeo
Constraint Violating Yak Guru
287 Posts |
Posted - 2007-10-05 : 05:43:07
|
| Sorry got myself confused with this, field 2 is in a seperate table. So what I need to do is:Update Table1 SET Field1 = (SELECT Field2 FROM Table2 WHERE Table2.id = Table1.id)WHERE Table1.Make = "BMW"Is that statement correct?Thanks |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-10-05 : 05:49:15
|
Or still better:Update t1Set Field1 = t2.Field2From Table t1 join Table2 t2 on t1.id = t2.idwhere t1.Make = 'BMW' Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
|
|
|