I am sure that this must be quite a common problem so I would guess that Microsoft have already solved the problem. My Googling skills are just not up to scratch. I have a field that I want to order by, it is a varchar field, for example
- Q
- Num 10
- Num 1
- A
- Num 9
- Num 2
- F
Now I would expect the result to be
- A
- F
- Num 1
- Num 2
- Num 9
- Num 10
- Q
But it is not. It is as follows (Notice that Num 10 comes after Num 1 and not Num 9 as expected)
- A
- F
- Num 1
- Num 10
- Num 2
- Num 9
- Q
Now I know the reason for this so you don’t need to explain 🙂 But I can’t remember how to solve it or if there is a nice flag or command that I can use to get it right.
EDIT:
The examples above are just an example. The column could contain any value. Any combination of letters and digits. Is there a way to sort this humanly alphabetically instead of ASCII value alphabetically?
EDIT 2:
Thanks for the answers so far. I am talking about ANY arbitary data. If it were in a fixed position or preceded by something then it would easy and I wouldn’t be asking. I am asking for a general solution to this problem with ANY arbitary data. Not patterns, no rules, no nothing.
This is an age old problem of Ascii Sort Order vs. Natural Sort Order
See Sorting for Humans : Natural Sort Order for further details.