Remove numbers from field in ORDER BY

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • improvcornartist
    Recognized Expert Contributor
    • May 2007
    • 303

    Remove numbers from field in ORDER BY

    I have a table (books) with 2 columns (book_id, book).
    The table looks like:
    [HTML]19 Psalms
    20 Proverbs
    60 1 Peter
    61 2 Peter[/HTML]
    I want to sort this by text first, then number if a book has a number. So the sorted data would look like:
    [HTML]60 1 Peter
    61 2 Peter
    20 Proverbs
    19 Psalms[/HTML]
    My query is
    Code:
    SELECT book
    FROM books
    ORDER BY trim(replace(replace(replace(book,'3',''),'2',''),'1','')), book
    This works, but isn't there a better way?
  • improvcornartist
    Recognized Expert Contributor
    • May 2007
    • 303

    #2
    My problem with this query is that replace is a VBA function, so it doesn't work when I try the query outside Access. Is there another way to do this?

    Comment

    • missinglinq
      Recognized Expert Specialist
      • Nov 2006
      • 3533

      #3
      "My problem with this query is that replace is a VBA function, so it doesn't work when I try the query outside Access. Is there another way to do this??"

      Where exactly are you trying the query "outside of Access?"

      Linq ;0)>

      Comment

      • improvcornartist
        Recognized Expert Contributor
        • May 2007
        • 303

        #4
        Sorry I didn't specify. I'm trying to use VBScript. Even within Access, I would like to find any better way to sort the data.

        Comment

        Working...