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
 General SQL Server Forums
 New to SQL Server Programming
 Order By Woes

Author  Topic 

DavidChel
Constraint Violating Yak Guru

474 Posts

Posted - 2009-02-16 : 11:56:57
If you have 3 values 'Direct' 'Indirect' and 'Engineering' and you want your results ordered by those values, how can you do it? If you choose ascending, the alphabetical order is not the "correct" order.

Can you specify exactly the correct order to be shown?

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-02-16 : 12:10:33
Like this:
Case col  when 'Direct' then 0
when 'Indirect' then 1
when 'Engineering' then 2
Else col
Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-02-16 : 12:13:50
Is this what you meant ?


select * from(
select 'Direct' col
union
select 'Indirect'
union
select 'Engineering'
) t
order by replace(replace(replace(col,'Engineering',3),'Indirect',2),'Direct',1) asc
Go to Top of Page
   

- Advertisement -