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 |
|
caelwind
Starting Member
3 Posts |
Posted - 2008-06-12 : 15:59:47
|
Will this work???Update [table1] Set [table1].[field1] = [table2].[field3]Where [table1].[field1] = [table2].[field2]I have a temp table [table2] with the corrected value [field3] in itI need to update every row in [table1] where [field1] matches the incorrect [field2] in [table2]If not, please point me in the right direction Thanks,Caelwind |
|
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2008-06-12 : 16:07:46
|
| It should work.. are you getting any errors?Chiraghttp://www.chirikworld.com |
 |
|
|
Van
Constraint Violating Yak Guru
462 Posts |
Posted - 2008-06-12 : 16:09:36
|
| Will probably need a FROM clause in there... |
 |
|
|
caelwind
Starting Member
3 Posts |
Posted - 2008-06-12 : 16:10:45
|
| No errors, havent even put it on the SQL server yet, just thought I'd run it by everyone before I went forward. |
 |
|
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2008-06-12 : 16:13:18
|
| [code]Aha..ya it requires an From clause ..Update t1Set t1.[field1] = t2.[field3]From [table1] t1 Inner Join [table2] t2Where t1.[field1] = t2.[field2][/code]Chiraghttp://www.chirikworld.com |
 |
|
|
caelwind
Starting Member
3 Posts |
Posted - 2008-06-13 : 10:24:48
|
Got it working. . . Here is the working query for reference. UPDATE [table1] SET [table1].[Field1] = [table2].[field2] FROM [table1] INNER JOIN [table2] ON [table1].[Field1] = [table2].[field3] WHERE [table1].[Field1] = [table2].[field3] Not sure if I needed the Where statement, but I just wanted to be sure it was only hitting the data I wanted. Thanks everyone for all your help. Caelwind |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-13 : 10:50:53
|
quote: Originally posted by caelwind Got it working. . . Here is the working query for reference. UPDATE [table1] SET [table1].[Field1] = [table2].[field2] FROM [table1] INNER JOIN [table2] ON [table1].[Field1] = [table2].[field3] WHERE [table1].[Field1] = [table2].[field3] Not sure if I needed the Where statement, but I just wanted to be sure it was only hitting the data I wanted. Thanks everyone for all your help. Caelwind
WHERE not needed because the join is already matching based on same criteria. |
 |
|
|
|
|
|