Skip to content
Advertisement

Sql Server query varchar data sort like int

I have one table like

Data Like

Now I want to sort table by amount but one problem is amount is varchar so it sort table like this

but i want result like this

what should i do ?

Advertisement

Answer

Cast amount column into Numeric in ORDER BY clause while selecting:

Result:

Id amount
3 10000
2 4568
1 2340

See this SQLFiddle

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement