create table #temp ( id int, value int) insert into #te...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Reverse Engineering Meta

Q&A about the site for researchers and developers who explore the principles of a system through analysis of its structure, function, and operation

create table #temp (
id int,
value int)


insert into #temp values (1, 1)
insert into #temp values (2, 2)
insert into #temp values (3, 3)

declare @sum int
declare @biggest int
select @biggest = max(id) from #temp

while @biggest != 0
begin
  select @sum = @sum + value from #temp where id = @biggest
  select @biggest = @biggest - 1
  select @sum
end

select @sum

Enter Parameters

Options:
Switch to main site
loading Hold tight while we fetch your results