How to sort AlphaNumerics values in SQL Server?
Column Name [Revision] with Alphanumerics.
Type – varchar(5)
Sample Data as follows:
A B 1 10 2 30 4 5 6 7 10 C D
Sort Revisions by Order By clause:
Select Revision from [#Table1]
Type – varchar(5)
Sample Data as follows:
A B 1 10 2 30 4 5 6 7 10 C D
Sort Revisions by Order By clause:
Select Revision from [#Table1]
ORDER BY CASE WHEN Revision LIKE '%[^0-9]%' THEN 99999
ELSE CONVERT(INTEGER,Revision) END, Revision
Above query select revision and if revision is not numeric value, assigns 99999 values for nonnumeric data. If Revision has numeric value it converts into Integer and Orders the Revision value.
Comments