I tracked a status of a record in a text field and wanted to sort the results in a specific order. For example I want “active” to show before “rejected” and “deleted” to show up last, etc… It turns out it was pretty easy to do in SQL. Here it is:

select * from viewoffers where itemid=@ItemId

order by

    case status

    when ‘active’ then 1

    when ‘rejected’ then 2

    else 99

end

This entry was posted on Friday, May 25th, 2007 at 10:45 am and is filed under Random. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.