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 |
|
inibhreaslain
Starting Member
19 Posts |
Posted - 2009-03-23 : 15:32:56
|
| I have two table. They both use a unique key LogID where t1.LogID = t2.LogID.I wish to update some columns in t1 with values from columns in t2 AND some t2 columns with other t2 values.ie...UPDATE Table1 t1, Table2 t2SET t1.col1 = t2.cola,t1.col2 = t2.colb,t2.cola = t2.colc,t2.colb = t2.cold,t2.colc = t2.cole,t2.cold = t2.colfwhere t1.LogID = t2.LogIDand t1.col1 is null |
|
|
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts |
Posted - 2009-03-23 : 15:35:23
|
| Use 2 update statements. One for each table. |
 |
|
|
Vinnie881
Master Smack Fu Yak Hacker
1231 Posts |
Posted - 2009-03-23 : 16:03:42
|
[code]Update t1SET t1.col1 = t2.cola ,t1.col2 = t2.colbfrom Table1 t1inner join Table2 t2on t1.LogID = t2.LogIDUpdate t2set t2.cola = t2.colc ,t2.colb = t2.cold ,t2.colc = t2.cole ,t2.cold = t2.colfFrom Table2 T2[/code] Success is 10% Intelligence, 70% Determination, and 22% Stupidity.\_/ _/ _/\_/ _/\_/ _/ _/- 881 |
 |
|
|
|
|
|