Thread: Swap Sort Order

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Posts
    2
    Rep Power
    0

    Arrow Swap Sort Order


    Hi, I am looking for some help on an application that I am developing.

    What I am trying to accomplish is to change the sortorder column from 1 to 9 and then have all the other sort records update themselves. IE. 1 becomes 9, 2 becomes 1, 3 becomes 2,....., 9 becomes 10, 10 becomes 11, etc...
    Any help would be appreciated!!!!!
  2. #2
  3. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,196
    Rep Power
    4279
    very sketchy description, not sure i understand

    might have helped if you could say what it's for

    Code:
    select foo
         , bar
      from yourtable
    order 
        by case 
    when sortfield=1 then 9
    when sortfield<9 then sortfield-1
    when sortfield>8 then sortfield+1
    end
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

IMN logo majestic logo threadwatch logo seochat tools logo