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)
 i have a problem regarding update statement

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 respectively


de26i table contains

name user_id de1
sairam sai 25

de27i table contains
name user_id de2
sairam saib 25

now i want both these updated values to be store in de28i which contains
de28i table contains
name 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 de26i
WHERE de26i.name LIKE de28i.name) + (SELECT [user_id de2] FROM de27i
WHERE de27i.name LIKE de28i.name)


I dont tested it, so I can't say 100%ly that it works...
Go to Top of Page

drymchaser
Aged Yak Warrior

552 Posts

Posted - 2004-05-25 : 09:33:57
update a
set a.data1 = (isnull(b.de1, 0) + isnull(c.de2, 0))
from de28i a join de1 b on a.name = b.name
join de2 c on a.name = c.name
Go to Top of Page

Pethron
Starting Member

10 Posts

Posted - 2004-05-25 : 09:43:48
quote:
Originally posted by drymchaser

update a
set a.data1 = (isnull(b.de1, 0) + isnull(c.de2, 0))
from de28i a join de1 b on a.name = b.name
join 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 a
set a.data1 = (isnull(b.de1, 0) + isnull(c.de2, 0))
from de28i a join de26i b on a.name = b.name
join de27i c on a.name = c.name
Go to Top of Page
   

- Advertisement -