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)
 Yet Another Order By Question

Author  Topic 

danielhai
Yak Posting Veteran

50 Posts

Posted - 2002-09-11 : 19:01:41
given this statement:


select column1,
column2,
column3,
column4
from thetable
order by
(case @OrderBy
when 1 then column1
when 2 then column2
when 3 then column3
when 4 then column4
end)

this is what i'm doing now:

if @Desc = 1
select column1,
column2,
column3,
column4
from thetable
order by
(case @OrderBy
when 1 then column1
when 2 then column2
when 3 then column3
when 4 then column4
end)
DESC
else
select column1,
column2,
column3,
column4
from thetable
order by
(case @OrderBy
when 1 then column1
when 2 then column2
when 3 then column3
when 4 then column4
end)





is there a way to have it be sorted by desc within the case statement? or do I have to have it split out into two selects, with one adding the desc?



Edited by - danielhai on 09/11/2002 19:22:21

Edited by - danielhai on 09/11/2002 19:22:38

M.E.
Aged Yak Warrior

539 Posts

Posted - 2002-09-11 : 19:15:20
Dynamic SQL is the only way I can see this happening otherwise.

-----------------------
Take my advice, I dare ya
Go to Top of Page
   

- Advertisement -