Click here to Skip to main content
15,903,175 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a table containing 1 to 121 numbers only.

i want to order it by number

Example

i have a table named tbl_numbers having only one field number
the filed number contains 1 to 121 numbers consecutively

i want to show it like
1
2
3
4
5
6
7
8 etc

i used this query

select number from tbl_numbers order by number


its showing like this

1
10
11
12
13
2
3
4
5
6
7
8
9 etc

that is it is jus ttaking the first digit only..



can anyone help me to solve this?

it will be a great one

Kishore R
Posted

It because your number column datatype in sql is VARCHAR r any other. It should be INT. Then only sorting will work.
 
Share this answer
 
Comments
Dalek Dave 24-Nov-10 5:05am    
Good Answer, Well Spotted.
Try this:
SQL
SELECT number FROM tbl_numbers ORDER BY number+0
 
Share this answer
 
Comments
Hiren solanki 24-Nov-10 8:34am    
Good answer!
Your Solution Here:

SQL
SELECT Number FROM tbl_Numbers ORDER BY Convert(INT,Number)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900