declare @t table(number int) insert into @t values (1), (2)

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

declare @t table(number int)
insert into @t values (1), (2)

declare @sum bigint = 0

select @sum = @sum + number
    from (select top 2 number from @t order by number) subquery
    order by number desc

select @sum

Enter Parameters

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