How to sort data by alphanumeric values
4 answers
What you want is called "natural". For Microsoft SQL Server 2005 see this question . For other languages ββsee (For example) this other question .
+1
source to share
If we can assume that the data values ββonly contain the letter d and a numeric value, you can also use:
select column from YourTable
order by convert(int, replace(column, 'd', ''))
If it contains any other letters, then this method quickly becomes unusable:
select column from YourTable
order by convert(int,
replace(replace(replace(replace(replace(
column, 'a', ''),
'b', ''),
'c', ''),
'd', ''),
'e', '')
)
0
source to share