How do I ORDER BY Alpha Numeric?
Posted on 2006-06-20
I have a problem with sorting a alpha numeric field.
location_tag (type nvarchar(50))
If I do :
"SELECT location_tag from location ORDER BY location_tag"
How do I make it so it sorts the numeric values as integers then sort the character values?
I have tried:
SELECT location_tag FROM location ORDER BY CASE ISNUMERIC(location_tag) WHEN 1 THEN CONVERT(INT, location_tag) ELSE location_tag END
But it would produce an error:
Syntax error converting the nvarchar value 'Pad A' to a column of data type int.
Any Help is appreciated.
I know that i shouldnt be using a mixed field that contains both alpha and numeric, but that is how the client wants it. Because sometimes the values are numeric, somtimes its characters, sometimes both.
It is when its both that i am encountering a problem.