Converting Text number into number 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 

Published by


A developer,teacher and a blogger obsessed with Python,Dart and open source world from India

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.