declare @t table (SortColumn int) insert @t values (1),...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for programmers

-- Enter Query Title
-- Enter Query Description


declare @t table (SortColumn int)
insert @t values (1), (2), (3)
declare @asc bit
set @asc = 0

select  row_number() over (order by
--            case when 1=1 then SortColumn end,
--            case when 1=0 then SortColumn end desc) rn1
            case when @asc=1 then SortColumn end,
            case when @asc=0 then SortColumn end desc) rn1
,       *
from    @t

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results
:records returned in :time ms:cached