Just curious, is it possible to achieve this ordering:
X5
X30
rather than this resulting from the 'out of the box' ORDER BY:
X30
X5
Just curious, is it possible to achieve this ordering:
X5
X30
rather than this resulting from the 'out of the box' ORDER BY:
X30
X5
Assuming the all values consist of a non-numeric part which may be followed by a numeric part, you can do something like this (using the AdventureWorks2008R2 sample database):
SELECT Name,
LEFT(Name,LEN(Name)-NULLIF(PATINDEX('%[^0-9]%',REVERSE(Name)),0)+1) AS StringPart,
CONVERT(FLOAT,RIGHT(Name,NULLIF(PATINDEX('%[^0-9]%',REVERSE(Name)),1))) AS NumericPart
FROM Production.Product
ORDER BY StringPart, NumericPart
This will provide "incorrect" results if the assumptions are not met (for example if the non-numeric part is missing, or if after the numeric part there is another string part, etc).