Re: Updating several fields in a table with a select statement

From: Hugo Kornelis (hugo_at_pe_NO_rFact.in_SPAM_fo)
Date: 11/29/04


Date: Mon, 29 Nov 2004 22:59:47 +0100

On Mon, 29 Nov 2004 10:09:18 -0800, Chip wrote:

>Hi,
>
>Is there a way in T-SQL to update several fields of a table with fields from
>another table using a select statement based on a key? I remember doing that
>in Oracle. If so, can you please give me the syntax. Thanks.

Hi Chip,

Is this the syntax you are looking for?

UPDATE a
SET Column1 = b.Column1,
           ....
           ColumnN = b.ColumnN
FROM FirstTable AS a
INNER JOIN SecondTable AS b
      ON b.??? = a.???
WHERE ....

Note that this syntax is proprrietary T-SQL, not ANSI-standard, and
therefore not portable to other platforms. Note also that the results may
not be as expected if a row in FirstTable matches more than one row in
SecondTable.

Best, Hugo

-- 
(Remove _NO_ and _SPAM_ to get my e-mail address)


Relevant Pages

  • Re: Can I put chunk of text from READTEXT into a variable ?
    ... So I finally give up the READTEXT syntax, and now working on another version using the suggested SUBSTRING syntax. ... application interface But I also expect T-SQL can be a more useful language and able to handle wider range of application. ... BTW, as a near-novice of T-SQL, while trying to do programming with the SUBSTRING syntax, I found some other limitation of T-SQL that seems quite annoying, where I want to share with you all here. ... Just hope SQL Server can evolve and become better and better ...
    (microsoft.public.sqlserver.programming)
  • Elseif
    ... Hi can I use Elseif in T-SQL? ... syntax. ...
    (microsoft.public.sqlserver.programming)
  • Re: Elseif
    ... > Hi can I use Elseif in T-SQL? ... > syntax. ...
    (microsoft.public.sqlserver.programming)
  • Re: EXCEPT Syntax
    ... Die Beschreibung bezieht sich dort auf die Analysis Services ... In T-SQL ist der Befehl nicht realisiert. ... mit der EXISTS Syntax realisieren, ...
    (microsoft.public.de.sqlserver)