Sort By Name Except Other

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • andrewteg
    New Member
    • Aug 2007
    • 22

    Sort By Name Except Other

    I am trying to run a basic SELECT * FROM Table ORDER BY Name query but I want "Other" to be at the end of my list instead of alphabetically. Assuming I know that the text is Other and the ID # for Other, is it possible to do this with SQL Server or would I have to do it on the front end with the script?

    Thanks,
    Andrew
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    Originally posted by andrewteg
    I am trying to run a basic SELECT * FROM Table ORDER BY Name query but I want "Other" to be at the end of my list instead of alphabetically. Assuming I know that the text is Other and the ID # for Other, is it possible to do this with SQL Server or would I have to do it on the front end with the script?

    Thanks,
    Andrew
    try:
    Code:
    select * from 
    (
    select
    sortorder = case whateverfield = 'Other' then 2 else 1 end,
    mytable.* from mytable
    ) A order by sortorder asc, othersortfield
    or

    Code:
    select * from mytable 
    order by case when thisfield = 'OTHER' then 2 else 1 end asc, thisfield
    the first one would be slower...am just demonstrating that it's possible

    -- ck

    Comment

    Working...