Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I Want to retrieve data from database by ascending order. In Database numbers are stored as
1 2 3 1 2 3 1 1 2 3 4 .... 10
but when i run my query then it show as
1 1 1 1 10 2 2 3 3 3 4
My query is
SQL
SELECT * FROM tblDetail
    WHERE USERID = @uID
ORDER BY day ASC

Here day is number 1 2 3 4 etc
i.e on day 1 on day 2

[Edit]Code block added[/Edit]
Posted
Updated 18-Nov-12 4:45am
v2

The problem is almost certainly that you have stored the data as a string, rather than a number. In strings, "10" comes before "2" because it starts with an earlier character: i.e. 1 is less than 2

Change your database: use numbers where possible, string comparisons do not work the same way as integer comparisons!
 
Share this answer
 
ORDER BY Clause will return 1 1 1 1 2 2 3 3 3 4 10 ... not 1 1 1 1 10 2 2 3 3 3 4 .
I think your field type is not numeric type.

SQL
Select * from tblDetail order by  convert(int, day)


If this solution not fulfill your requirement, give details and also table structure.
 
Share this answer
 
I would do something like this:

SQL
SELECT *, CONVERT(int, your_column) AS your_column_int
FROM your_table
ORDER BY your_column_int
 
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