gopi
gopi

Reputation: 61

order by case in sql 2005 server

One of the column in my table like this:

Symbol  
586fast                
urgent         
243late  
296fast  
122late   
155fast   

I need urgent in first then records with fast order asc then records with late order asc like this:

urgent  
586fast  
296fast  
155fast  
243late   
122late

I am getting urgent in first row,records with fast and late but they are not in asc order

    ORDER BY CASE 
when Symbol like '%FUT' then 1 
when Symbol like '%CE' then 2 
when Symbol like '%PE' then 3 
else 4 end  

Upvotes: 2

Views: 45

Answers (1)

Mudassir Hasan
Mudassir Hasan

Reputation: 28741

After ordering using case statement provide further ordering by Symbol column itself

ORDER BY CASE 
when Symbol like '%FUT' then 1 
when Symbol like '%CE' then 2 
when Symbol like '%PE' then 3 
else 4 end, Symbol asc  

Upvotes: 1

Related Questions