Click here to Skip to main content
11,485,334 members (80,730 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET SQL
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
	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 18-Nov-12 5:37am
Edited 18-Nov-12 5:45am
ProgramFOX154.7K
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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.

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

If this solution not fulfill your requirement, give details and also table structure.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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!
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I would do something like this:

SELECT *, CONVERT(int, your_column) AS your_column_int
FROM your_table
ORDER BY your_column_int
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 375
1 Maciej Los 365
2 C#developer.asp 204
3 Mehdi Gholam 190
4 OriginalGriff 149
0 Sergey Alexandrovich Kryukov 8,819
1 OriginalGriff 7,982
2 Sascha Lefèvre 3,199
3 Maciej Los 2,841
4 Richard Deeming 2,370


Advertise | Privacy | Mobile
Web03 | 2.8.150520.1 | Last Updated 18 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100