Results 1 to 4 of 4
  1. #1
    jazfunk is offline Novice
    Windows 7 64bit Access 2002
    Join Date
    Apr 2011
    Location
    Detroit, MI
    Posts
    2

    Sort query by a column/field with number as string value

    The attached text file gives an example of the sorting problem I'm encountering.



    I'm sorting on a string value column:

    01-01
    01-02
    02-01
    02-02
    03-01
    03-02
    etc.

    (The first set of numbers represent page numbers in a set of plan sheets. The second set of numbers represent items on each page. The number of pages and items can vary for each project.)

    Everything is fine until you get to 3 digit prefix/page numbers (i.e 100-01, etc.). In the text file are 400+ lines of values like the above example, sorted Ascending. The result is not what is desired.

    This has been difficult, at best, to put into words. I'm hoping once you see the list you'll see what I want it to do... sort by the numbers left of the "-" (Page#) and within each of those sort by the the numbers to the right of the "-" (Items on a page).

    Can anyone point me in the right direction for sorting these Qry's?

  2. #2
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Create a calculated field in your query by prep-ending a couple of zeros to the field, then take the right 6 characters. The query would look something like:

    Code:
    SELECT Right("00" & [YourField],6) AS SortedNo
    FROM YourTable
    ORDER BY Right("00" & [YourField],6);
    Change the blue to your field and table names

  3. #3
    jazfunk is offline Novice
    Windows 7 64bit Access 2002
    Join Date
    Apr 2011
    Location
    Detroit, MI
    Posts
    2

    Solved!

    That worked brilliantly. Very simple. Thank you.

  4. #4
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You're welcome

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Cannot sort on column contents (Access 2007)
    By jameshurrell in forum Access
    Replies: 6
    Last Post: 03-15-2011, 10:57 AM
  2. Replies: 5
    Last Post: 03-10-2011, 02:19 PM
  3. Query Random Number Column Manipulation
    By gmontano in forum Queries
    Replies: 4
    Last Post: 10-05-2010, 01:36 PM
  4. Replies: 1
    Last Post: 03-22-2010, 03:37 PM
  5. Sort by even or odd number
    By sammer021486 in forum Queries
    Replies: 7
    Last Post: 11-23-2009, 12:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums