Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
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
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' colunion select 'Indirect' union select 'Engineering' ) torder by replace(replace(replace(col,'Engineering',3),'Indirect',2),'Direct',1) asc