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]
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

Popular posts from this blog

Windows Azure Package Build Error: The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.

Resource ID : 1. The request limit for the database is 180 and has been reached.

How to get Client's Location using IPAddress