Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 using subquery with update

Author  Topic 

bilencekic
Posting Yak Master

121 Posts

Posted - 2006-05-05 : 05:21:37
table Money
KID---Money
1---1000
2---2000
3---3000

table S_Money

KID---sMoney
1---10
2---20
3---30


i want an update query to select all from table s_Money and update them to table Money
result will be like this

table Money
KID---Money
1---1010
2---2020
3---3030

update Money set Money = (subqery)

i tried this but give subqeruy error. Cant we use subquery with update command?

MS BLESS US

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-05-05 : 05:26:28
[code]
update m
set m.Money = m.Money + s.Money
from Money m inner join S_Money s
on m.KID = s.KID
[/code]


KH

Go to Top of Page

bilencekic
Posting Yak Master

121 Posts

Posted - 2006-05-05 : 05:31:07
ok i have fixed it without innerjoin

MS BLESS US
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-05-05 : 05:34:09
with subquery ?

update m
set m.Money = m.Money + (select Money from S_Money x where x.KID = m.KID)
from Money m



KH

Go to Top of Page
   

- Advertisement -