Re: Sorting on mixed text-numeric



On Sat, 30 Jun 2007 12:21:45 -0700, wizard_chef <wizard_chef@xxxxxxxxxxx>
wrote:

In an Access query I am trying to sort on a text field containing
strings like mx1, mx2, ... mx9, mx10, mx11, ...
What I get is a sort like: mx1, mx10, mx11, ... etc. It seems I need
to convert these to numeric but I have tried cInt and a number of
other VBscript conversion functions, and I always get a type-conflict
error.

How can I convert this field in the query so that it will sort
treating the numeric part of the string as numeric rather than
alphabetic?? i.e., mx1, mx2, mx3, ... mx9, mx10, mx11, ... and so on.

If the alphabetic part is always two characters, you can use a calculated
field

Sortkey: Val(Mid([textfield], 3))

to extract a Number datatype value which will sort correctly.

If the number can occur in variable places in the text string... you may want
to consider redesigning your table. Fields should be "atomic" with only one
value; it seems this field has a text portion and a number portion, which
ideally should be in two fields (which can be concatenated at will for data
display).

John W. Vinson [MVP]
.



Relevant Pages

  • Split Single Address Field into Component Parts
    ... would make a copy of the database before making any ... would subtract that part of the string from the working ... I ran an update query to extract the portion of the ...
    (microsoft.public.access.queries)
  • Split Single Address Field into Component Parts
    ... >address field using an update query. ... >string functions. ... I ran an update query to extract the portion of the ...
    (microsoft.public.access.queries)
  • Re: atoi return
    ... the "initial portion of the string" can be ... sequence of white-space characters (as specified by the isspace ... terminating null character of the input string. ...
    (comp.lang.c)
  • Re: Find Replace
    ... pin" to "end vss". ... And then delete some lines within that portion. ... string buffer the [split ... ... puts $line should be moved into the if statement, ...
    (comp.lang.tcl)
  • Re: Why strNlen is not in Std ?
    ... "Compare a portion of one string to a portion of another." ... Expressed in this posting are my opinions. ... to opinions held by my employer, Sun Microsystems. ...
    (comp.std.c)