A A
RSS

Custom sort order in a SQL statement

Fri, May 25, 2007

Random

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

Tags:

  • Q
    thank you!
  • me
    cool shit man
blog comments powered by Disqus
Advertise Here
The Most Intelligent Add-In To Visual Studio Happy fan of

What I'm Doing...

Yonkly Open Source

Sign up for my newsletter




* = required field

powered by MailChimp!

megree Widget

Apparently, I am connected to Obama. Check this out...
My path to Obama

Cyber Identity