Nick LaMarca
Nick LaMarca

Reputation: 8188

Order By Problem T-Sql

I have a sql statement I am using a simple sort such as the following

Select numbers
From theTable
Order By numbers

What I get in return is the following

1
11
12
14
2
21
22
23
3
35
37
etc...

I want it to be ordered in normal order

1
2
3
4
5
6
etc...

Upvotes: 0

Views: 261

Answers (2)

Justin Niessner
Justin Niessner

Reputation: 245399

The column you are selecting isn't stored as a numeric value. You need to cast it to a some kind of number before orderby will behave the way you want.

It should be as easy as:

select numbers from order orderby cast(numbers as int)

As long as long as all the values in that column cast properly.

Upvotes: 4

Ian Jacobs
Ian Jacobs

Reputation: 5501

what's the datatype of the column storing the numbers? Convert/cast it to an int and you should get what you expect.

Upvotes: 0

Related Questions