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 |
Cyclonik
Posting Yak Master
114 Posts |
Posted - 2006-01-26 : 14:38:46
|
What is the correct syntax for a correlated update in SQL Server?Here is the Oracle syntax which does not work in SQL Server 2k:UPDATE table1 t_alias1 SET column = ( SELECT expr FROM table2 t_alias2 WHERE t_alias1.column = t_alias2.column); |
|
Srinika
Master Smack Fu Yak Hacker
1378 Posts |
Posted - 2006-01-26 : 14:45:37
|
UPDATE table1 SET t_alias1.column = t_alias2.expr FROM table1 t_alias1, table2 t_alias2 WHERE t_alias1.column = t_alias2.column |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-01-26 : 19:56:28
|
Or use the table alias name in the UPDATEUPDATE t_alias1SET t_alias1.column = t_alias2.exprFROM table1 t_alias1, table2 t_alias2WHERE t_alias1.column = t_alias2.column ----------------------------------'KH' |
 |
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2006-01-26 : 20:56:05
|
I prefer using INNER JOIN syntax:update table1 set columna = table2.exprfrom table1 inner join table2 on table1.column1 = table2.column1 CODO ERGO SUM |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-01-27 : 01:29:37
|
Also I prefer using Alias names when you use JOINs  update t1set t1.columna = t2.exprfrom table1 t1 inner join table2 t2 on t1.column1 = t2.column1 MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|