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.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2004-05-25 : 08:36:48
|
| saimram writes " i have two tables namely de26i and de27i which are taking values from other table called hcfa table and now i want to update the sum of both de26i and de27i to a another table called de28i where i need to store the sum of values of de26i and de27i but i could not update themin de28i though i can update both individually in de26i and in de27 i respectivelyde26i table containsname user_id de1sairam sai 25de27i table containsname user_id de2 sairam saib 25now i want both these updated values to be store in de28i which contains de28i table containsname data1(sum of de26i.de1 + de27i.de1) sairam 50" |
|
|
Pethron
Starting Member
10 Posts |
Posted - 2004-05-25 : 09:28:23
|
I'm not sure if I understand the same that you are asking, but my solution would be like this:UPDATE de28i SET data1 = (SELECT [user_id de1] FROM de26iWHERE de26i.name LIKE de28i.name) + (SELECT [user_id de2] FROM de27iWHERE de27i.name LIKE de28i.name) I dont tested it, so I can't say 100%ly that it works... |
 |
|
|
drymchaser
Aged Yak Warrior
552 Posts |
Posted - 2004-05-25 : 09:33:57
|
| update aset a.data1 = (isnull(b.de1, 0) + isnull(c.de2, 0))from de28i a join de1 b on a.name = b.namejoin de2 c on a.name = c.name |
 |
|
|
Pethron
Starting Member
10 Posts |
Posted - 2004-05-25 : 09:43:48
|
quote: Originally posted by drymchaser update aset a.data1 = (isnull(b.de1, 0) + isnull(c.de2, 0))from de28i a join de1 b on a.name = b.namejoin de2 c on a.name = c.name
Ok, this solution would be better than mine, but there is a little mistake. Following would work:update aset a.data1 = (isnull(b.de1, 0) + isnull(c.de2, 0))from de28i a join de26i b on a.name = b.namejoin de27i c on a.name = c.name |
 |
|
|
|
|
|