|
Posted by Erland Sommarskog on 01/10/06 13:27
Serge Rielau (srielau@ca.ibm.com) writes:
> In SQL92 (should work in MS SQL Server and any other SQL based RDBMS):
>
> UPDATE T SET (c1, c2) = (SELECT c1, c2 FROM S WHERE pk = T.pk)
> WHERE EXISTS(SELECT 1 FROM S WHERE pk = T.pk)
This does not work in SQL Server. The syntax is:
UPDATE T
SET c1 = S.c1,
c2 = S.c2
FROM T
JOIN S ON T.pk = S.pk
The syntax is not very portable (works on Sybase too), but certainly
simple to grasp.
--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
[Back to original message]
|