Alphanumeric sort order 1,10,11,12,2,3,4

Posted by DimitriG4 on 14-Jun-2010 13:47

I have a field that usually contains alphanumeric values, but not always. So "numbers" end up sorted as 1,10,11,12,2,3,4,.... instead of 1,2,...10,11,12

Other than avoiding using "digits only" is there a way to cause an index to sort "properly" ?

All Replies

Posted by Admin on 14-Jun-2010 13:54

Other than avoiding using "digits only" is there a way to cause an index to sort "properly" ?

Prefixing with "0" or use an additional (numeric) field that you maintain under the covers (depending on your architecture in a Trigger, SDO or Business Entity) that is indexed and provides the desired sort.

Posted by Thomas Mercer-Hursh on 14-Jun-2010 14:05

Bottom line, if you want it to sort like a number, define it as a number.  By normal rules, it *is* sorting properly.

Which said, as Mike says, you can zero pad when you fill the list.  I.e., ttStuff.chSortField = string(inSomeNumber,"9999999").

Posted by DimitriG4 on 14-Jun-2010 15:55

Thanks, I wanted to make sure there wasn't a secret handshake I was missing

Posted by Thomas Mercer-Hursh on 14-Jun-2010 16:02

It's the DWIWNWIS* switch!

*Do What I Want, Not What I Say"

This thread is closed