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)
 update slow

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2000-12-23 : 20:10:04
fulvio writes "I have 1 table called movimento where there is day by day moviment from account. There is another table called extrato that is resume the current spend of the month and the past months of the year

so in one update i need to put values in column realizado (how much spend in one month) and realizado_Ate (how much spend in the past months of the year). But this statement is very slow and the temp db overflow. I has (5000 rows per month)
the primary key are ct_codigo, ep_codigo e sc_codigo. for works i need to use where to get some rows.


declare @vano int
declare @vmes int
set @vano = 2000
set @vmes = 2

select @vano, @vmes

/* insert extrato select @vano, @vmes, s.ep_Codigo, s.ct_codigo, s.sc_codigo, s.titulo, 0, 0, 1, s.keytituloconta from contas s */

update extrato set realizado = (select sum(valor) from movimento where movimento.ep_codigo = extrato.ep_codigo and movimento.ct_codigo = extrato.ct_codigo and movimento.sc_codigo = extrato.sc_codigo and datepart(year, movimento.data) = @vano and datepart(month, movimento.data) = @vmes ), realizado_ate = (select sum(valor) from movimento where movimento.ep_codigo = extrato.ep_codigo and movimento.ct_codigo = extrato.ct_codigo and movimento.sc_codigo = extrato.sc_codigo and datepart(year, movimento.data) = @vano and datepart(month, movimento.data) < @vmes ) from extrato, movimento where extrato.sc_codigo = 43001"
   

- Advertisement -