sql - How do I order by on a varchar field that could contain numbers alphabetically? -


i sure must quite common problem guess microsoft have solved problem. googling skills not scratch. have field want order by, varchar field, example

  • q
  • num 10
  • num 1
  • a
  • num 9
  • num 2
  • f

now expect result be

  • a
  • f
  • num 1
  • num 2
  • num 9
  • num 10
  • q

but not. follows (notice num 10 comes after num 1 , not num 9 expected)

  • a
  • f
  • num 1
  • num 10
  • num 2
  • num 9
  • q

now know reason don't need explain :) can't remember how solve or if there nice flag or command can use right.

edit:

the examples above example. column contain value. combination of letters , digits. there way sort humanly alphabetically instead of ascii value alphabetically?

edit 2: answers far. talking arbitary data. if in fixed position or preceded easy , wouldn't asking. asking general solution problem arbitary data. not patterns, no rules, no nothing.

this age old problem of ascii sort order vs. natural sort order

see http://www.codinghorror.com/blog/archives/001018.html further details.


Comments

Popular posts from this blog

unicode - Are email addresses allowed to contain non-alphanumeric characters? -

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -