Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Microsoft SQL Server > Re: updating mu...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 5 Topic 11025 of 11517
Post > Topic >>

Re: updating multiple columns with subselect

by "Dan Guzman" <guzmanda@[EMAIL PROTECTED] > May 8, 2008 at 07:42 AM

> This is not sup****ted in MSsql.
>
> update T1 set (theUpdatedValue, theOtherValue) =
>      (select theTop, theValue from T2 where T2.theKey = T1.theID)
>
> Is there a workaround?

You can use the proprietary UPDATE...FROM syntax:

UPDATE T1
SET
    theUpdatedValue = T2.theTop,
    theOtherValue = T2.theValue
FROM T2
WHERE
    T2.theKey = T1.theID

Or with an alias:

UPDATE a
SET
    theUpdatedValue = b.theTop,
    theOtherValue = b.theValue
FROM T1 a
JOIN T2 b ON
    b.theKey = a.theID

-- 
Hope this helps.

Dan Guzman
SQL Server MVP
http://weblogs.sqlteam.com/dang/

"Leif Neland" <leif@[EMAIL PROTECTED]
> wrote in message 
news:4822d7e6$0$56781$edfadb0f@[EMAIL PROTECTED]
> This is not sup****ted in MSsql.
>
> update T1 set (theUpdatedValue, theOtherValue) =
>      (select theTop, theValue from T2 where T2.theKey = T1.theID)
>
> Is there a workaround?
>
> Other than doing it in a loop from eg asp, over either fields (one 
> statement
> per field), or over records (a query with a loop which for each row does
a
> select from one table, update other table with the selected values.)
>
>
 




 5 Posts in Topic:
updating multiple columns with subselect
"Leif Neland" &  2008-05-08 12:36:13 
Re: updating multiple columns with subselect
"Dan Guzman" &l  2008-05-08 07:42:28 
Re: updating multiple columns with subselect
"Leif Neland" &  2008-05-09 09:52:29 
Re: updating multiple columns with subselect
"Plamen Ratchev"  2008-05-08 09:37:43 
Re: updating multiple columns with subselect
--CELKO-- <jcelko212@[  2008-05-12 13:00:07 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Dec 3 1:05:40 CST 2008.