T.T.T. T.T.T. - 4 months ago 11
SQL Question

SQL ORDER chars numerically

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.

Answer

Try this:

ORDER BY CAST(thecolumn AS int)
Comments