How to properly sort alphanumeric data in SQL Server 2000
MS SQL Server 2000
I have a column in table A called Name. I want to sort the Name field. Many, but not all, entries for the start of a name will be KL followed by a number (KL 1234, KL 2, KL 323, etc.).
Table A
Name
Able
Bravo
KL 2
KL 323
KL 1234
Zebra
If i use
Select Name from A
Order by Name
I get
Able
Bravo
KL 1234
KL 2
KL 323
Zebra
I want to
Able
Bravo
KL 2
KL 323
KL 1234
Zebra
If it all started with KL, I could use
Select Name from A
Order by cast(replace(name, 'KL', '') as big int)
but this generates an "unble to cast name as large int" error for values ββthat do not start with KL
Thanks for any help.
0
source to share