I have a column of numbers stored as chars. When I do a ORDER BY for this column I get the following:
100
131
200
21
30
31000
etc.
How can I order these chars numerically? Do I need to convert something or is there already an SQL command or function for this?
Thank You.
The ORDER BY keyword is used to sort the result-set in ascending or descending order. The ORDER BY keyword sorts the records in ascending order by default. To sort the records in descending order, use the DESC keyword.
Try this:
ORDER BY CAST(thecolumn AS int)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With