W dniu 2013-06-11 10:56, grzehorz pisze:
> Mam coś takiego:
> WZ1 10
> WZ2 3
> WZ3 12
> WZ4 1
>
> I chciałbym uzyskać:
> WZ1 10 10
> WZ2 3 13
> WZ3 12 25
> WZ4 1 26
>
> Czytałem o klauzuli OVER, ale chyba nie bardzo to rozumiem,
W tym szczególnym wypadku masz 2 rozwiązania:
1 - kursor.
2 - update na tabeli, np.:
if OBJECT_ID('tempdb..#T') is not null
drop table #T;
create table #T (symbol varchar(10), value int, total int)
declare @Count int = 160160;
while @Count > 0
begin
set @Count = @Count - 1;
insert into #T
values ('W' + LTrim(Str(@Count)), @Count % 2 + 1, null);
end;
declare @total int = 0;
update T1
set @total = @total + T1.value, total = @total
from #T T1
select * from #T;
Wszelkie inne rozwiązania będą wysoce niewydajne.
--
PaSkol