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 4:37am
Edited 18-Nov-12 4:45am
ProgramFOX121.1K
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 OriginalGriff 554
1 Gihan Liyanage 338
2 RyanDev 268
3 Sergey Alexandrovich Kryukov 263
4 ChauhanAjay 220
0 Sergey Alexandrovich Kryukov 8,936
1 OriginalGriff 7,891
2 CPallini 2,603
3 Richard MacCutchan 2,121
4 Abhinav S 1,928


Advertise | Privacy | Mobile
Web04 | 2.8.140827.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