Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Database Servers
DB2InformixIngresMS SQLOraclePervasive.SQLPostgreSQLProgressSybase
Desktop Databases
FileMakerFoxProMS AccessParadox
General
General DB TopicsDatabase Theory
Related Topics
Java Development.NET DevelopmentVB DevelopmentMore Topics ...

Database Forum / General DB Topics / General DB Topics / August 2004

Tip: Looking for answers? Try searching our database.

Update more columns in MS SQL  Using a SELECT

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Marja - 17 Aug 2004 11:27 GMT
How can I do this in MS SQLserver (7.0 or 2000)

Update t1
SET (t1.v1, t1.v2) = ((SELECT  t2.v1, t2.v1       
                      FROM  t2
              WHERE t1.key= t2.key))
WHERE (t1.v3 LIKE '%')
--CELKO-- - 17 Aug 2004 20:01 GMT
>> How can I do this in MS SQLserver (7.0 or 2000) <<

Unfortunately, SQL Server does not have the SQL-92 syntax for a "SET
ROW()= ..." clause, so you do one column at a time.

UPDATE T1
  SET T1.v1 = (SELECT T2.v1
                 FROM T2
                WHERE T1.key = T2.key),
      T1.v2 = (SELECT T2.v2
                 FROM T2
                WHERE T1.key = T2.key)
WHERE T1.v3 LIKE '%'; -- strange predicate?

They have a version of the UPDATE.. FROM.. that appeared in Sybase and
other products.  Unfortunately, it is unpredictable, does not port and
does not match the semantivcs of other products with the same syntax.
Anith Sen - 26 Aug 2004 03:58 GMT
MS SQL Server supports a proprietary syntax for its UPDATE statement which
uses a FROM clause similiar to that in a SELECT statement. Thus you could
do:

UPDATE t1
  SET v1 = t2.v1,
      v2 = t2.v2
 FROM t2
WHERE t2.key = t1.key
  AND t1.v3 LIKE '%' ;

Signature

Anith

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.