Click here to Skip to main content
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
ProgramFOX127.3K
v2
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 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 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 535
1 OriginalGriff 275
2 Shweta N Mishra 244
3 BillWoodruff 235
4 Deepu S Nair 230
0 OriginalGriff 6,168
1 Sergey Alexandrovich Kryukov 5,818
2 DamithSL 4,958
3 Manas Bhardwaj 4,539
4 Maciej Los 3,755


Advertise | Privacy | Mobile
Web03 | 2.8.1411019.1 | Last Updated 18 Nov 2012
Copyright © CodeProject, 1999-2014
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