Converting Text number into number in Order By in SQL

Select * from emp order by code

[ here 'code' is a text field], result in unordered result due to the data type, in MS SQL and My SQL too.
To override this issue we can simply cast the field code using the cast operator.

select * from emp order by cast (code as int) Asc 

Comments

Popular posts from this blog

OLEDB Database connection string in C#.Net

How to get Computer Name using VB6 Code

SqlAlchemy[SQLite] database connection in Python-Flask