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
 SQL Server Development (2000)
 how to update several values from one table

Author  Topic 

CLages
Posting Yak Master

116 Posts

Posted - 2005-01-26 : 04:43:31
hi
how to update the sum of several values from one table in a Record from the same table

ex.

Table plano

pla_code pla_valueDeb pla_valueCre
12 100 0
13 30 0
14 20 0
15 40 0
16 0 0

i want to get the sum(pla_valueDeb) from plano where pla_code between 12 and 15

and update this result in Pla_valueCre of the pla_code = 16

the final result should be

pla_code pla_valueDeb pla_valueCre
12 100 0
13 30 0
14 20 0
15 40 0
16 0 190


tks

C. Lages

by the way i tried this and doesnt work

update plano

set pla_valueCre = Pla_valueCre +
Select pla_valueDeb from plano
where pla_code between 12 and 15

WHERE pla_code = 16

CLages
Posting Yak Master

116 Posts

Posted - 2005-01-26 : 04:59:13
i have already fixed
tks anyway

UPDATE PLANO
SET PLA_DEBMES = PLA_DEBMES +
(SELECT sum(

(pla_slddeb - pla_sldcre ) + (pla_debmes - pla_cremes)
)

from plano
where (pla_codigo BETWEEN 3000000000000 AND 3999999999999) and
(pla_empresa = 01)

)

WHERE PLA_CODIGO = 2211100000100 and
pla_empresa = 01
Go to Top of Page
   

- Advertisement -