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 |
|
Zath
Constraint Violating Yak Guru
298 Posts |
Posted - 2008-07-16 : 13:17:24
|
| I've done this once and I can't find my own sample, so here I am.I have 2 tables.First table (tbl1) to read from. tbl1Fld1 and tbl1Fld2Second table (tbl2) to update. tbl2Fld1 and tbl2Fld2Go through each row in tbl1. Read tble1Fld1 and find it's matchin tbl2Fld1. Then set tbl2Fld2 = tbl1Fld2 for that match.Seems simple enough and I've been trying it with a cursor with difficulty and I know there has to be an easier way.Thanks for anyone who can point me in the right direction.Zath |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-07-16 : 13:24:48
|
| You don't need a cursor or any kind of loop for this.UPDATE t2SET Fld2 = t1.Fld2 FROM Table2 t2INNER JOIN Table1 t1ON t2.Fld1 = t1.Fld1Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog |
 |
|
|
Zath
Constraint Violating Yak Guru
298 Posts |
Posted - 2008-07-16 : 13:34:40
|
| thanks. I knew ther was an easier way and it's been a while since I came across this scenario.Tim |
 |
|
|
|
|
|