dbTalk Databases Forums  

Update more columns in MS SQL Using a SELECT

comp.databases comp.databases


Discuss Update more columns in MS SQL Using a SELECT in the comp.databases forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Marja
 
Posts: n/a

Default Update more columns in MS SQL Using a SELECT - 08-17-2004 , 05:27 AM






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 '%')

Reply With Quote
  #2  
Old   
--CELKO--
 
Posts: n/a

Default Re: Update more columns in MS SQL Using a SELECT - 08-17-2004 , 02:01 PM






Quote:
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.


Reply With Quote
  #3  
Old   
Anith Sen
 
Posts: n/a

Default Re: Update more columns in MS SQL Using a SELECT - 08-25-2004 , 09:58 PM



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 '%' ;

--
Anith



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.