Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a table like this:
XML
col1  col2
 1     1
 2     1a
 3     2
 4     10
 5     a-1
 6     a-2

and the type of col2 is varchar, when I do order by col2 default,the result like this:
XML
col2
1
10
1a
2
a-1
a-2

but I want it like this:
XML
col2
1
1a
2
10
a-1
a-2

I don't want to do it using user-defined function.
help me!
Posted
Updated 23-Jun-10 23:46pm
v2
Comments
Kschuler 24-Jun-10 16:49pm    
I don't know if this will help (which is why I made this a comment instead of an answer) but you might want to research the PATINDEX
http://msdn.microsoft.com/en-us/library/ms188395.aspx

1 solution

What you want is a natural sort.
It isn't supported by any db that I'm aware of.

The reason for this is that most indexing of databases uses B-Tree index where B stands for Binary. Sorting uses the index.
So natural sorting would need a full table scan which in many cases would be a serious performance hit.

Here[^] is an article on how to implement natural sorting using C#.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900