Hi,
I have a table with various stock locations in (A1 to A200), but when
I sort the data in a query it sorts in the order A1, A10, A100, A2
etc. How can I sort it in to a logical order please (A1,A2 etc).
Many Thanks
Alec
That sort order IS CORRECT.
Since the field is a Text field, it's sorting in Text order; the orderA1,
A10, A100, A2 is being treated exactly the same as the order Ab, Aba, Abaa,
Ac. You wouldn't want to sort Ab, Ac, Ax, Aba, Abb would you?
If you want to sort by numerical order instead, and the field always has a
single text charactar followed by number, use the Val() function to create a
number:
ORDER BY Left([StockLocation], 1), Val(Mid([StockLocation], 2)
If the number might be embedded elsewhere in the location - e.g. if you have
values like A100, BCL3, BCL255, BA35 - you'll need to define your desired
sorting rule more clearly. You may want to store the text prefix in one field
and the numeric suffix in another.
On the other hand, if all locations have an A as the first character, consider
not storing the letter A at all - just use a Number type field and display it
with a Format such as
"\A#"
to display the letter A followed by the numeric value.
--
John W. Vinson [MVP]
Microsoft's replacements for these newsgroups:
http://social.msdn.microsoft.com/Forums/en-US/accessdev/
http://social.answers.microsoft.com/Forums/en-US/addbuz/
and see alsohttp://
www.utteraccess.com