Reply to Re: standard sql: update multiple rows.

Your name:

Reply:


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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация