SQL Server - order by clause to get required column format in sql server

Asked By ali shaik on 18-Jul-13 12:15 AM


  hi,
 

in my table i am having a column STATUS which is having records like this
 
ID NAME STATUS
101 ABCD 1
102 XYZ   2
103 XXX   3
104 DEF   4
 
i want to get output in the following format
 
ID NAME STATUS
102 XYZ    2
101 ABCD 1
104 DEF    4
103 XXX   3
Robbe Morris replied to ali shaik on 18-Jul-13 11:34 AM
Assuming you can't make changes to your schema, I think you'll have to convert the status code to something else
 
select id, name, status, 
  case when status = 2 then 1
     when status = 1 then 2
     when status = 4 then 3
     when status = 3 then 4
     else 0
  END
  as  statusorder
   from someTable
   order by 4
Ramendra Kumar replied to ali shaik on 24-Jul-13 03:14 AM
could you let me know what the format is this whatever you desired thats not poosiable simple with this structure you need to add a extra column named serial or something then you have to set the order into that, and then ordeby that column, i hope you understand, if you need extra help you may ping....