Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Ordering on numeric value of a text field
Message
 
 
À
06/01/2013 03:43:10
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2008
Application:
Web
Divers
Thread ID:
01561537
Message ID:
01561543
Vues:
66
This message has been marked as a message which has helped to the initial question of the thread.
>I have some fields in a table which contain numeric values but are defined as Char(3). So, in some SQLs, we have this ORDER BY Field1, Field2. Is there an easy way to obtain the order by as per the numeric value instead of their textual values? The problem is that values such as 1, 10, 11 which appear before 2, 3 instead of 1, 2, 3, 10, 11.

Try
ORDER BY CASE WHEN NumericField NOT LIKE '%[^0-9]%' THEN cast(NumericField as int) END, OtherFields
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform