469,602 Members | 1,912 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,602 developers. It's quick & easy.

sql SORT order not working on numbers?

Hello all... I'm using asp to get records from an access database, very
similar to the way datagrid would work. The title of each column in my table
is a link that alternates the sort order between ascending and descending...

my problem is that text WILL change its sort order just fine but nubers are
not always in order. ie: if sort order is ASC (ascending) I might see 2000,
234, 789 (should be ordered but its not). I'm guessing that ASP is handing
the string as a text string (?) and getting confused, is there a way to
force ASP into treating the string as numerals if this is the case? any
other ideas? Thanks so much.

here is one of my sql commands in case you want to see it. "sort" is a
variable containing the recordset to sort by depending on which link is
clicked. I hope I didn't confuse the whole issue because of a lack of
caffiene over here :)
strsql = "SELECT * FROM comments ORDER BY " & sort & " DESC"

Thanks of the help, much appreciated.
Eno

Jul 20 '05 #1
2 27966
What is the data type of the column containing the number?

--
Mark Schupp
--
Head of Development
Integrity eLearning
Online Learning Solutions Provider
ms*****@ielearning.com
http://www.ielearning.com
714.637.9480 x17
"Alpay Eno" <en*@spamsux.com> wrote in message
news:Mx********************@news4.srv.hcvlny.cv.ne t...
Hello all... I'm using asp to get records from an access database, very
similar to the way datagrid would work. The title of each column in my table is a link that alternates the sort order between ascending and descending...
my problem is that text WILL change its sort order just fine but nubers are not always in order. ie: if sort order is ASC (ascending) I might see 2000, 234, 789 (should be ordered but its not). I'm guessing that ASP is handing
the string as a text string (?) and getting confused, is there a way to
force ASP into treating the string as numerals if this is the case? any
other ideas? Thanks so much.

here is one of my sql commands in case you want to see it. "sort" is a
variable containing the recordset to sort by depending on which link is
clicked. I hope I didn't confuse the whole issue because of a lack of
caffiene over here :)
strsql = "SELECT * FROM comments ORDER BY " & sort & " DESC"

Thanks of the help, much appreciated.
Eno

Jul 20 '05 #2
> my problem is that text WILL change its sort order just fine but nubers
are
not always in order. ie: if sort order is ASC (ascending) I might see 2000, 234, 789 (should be ordered but its not).


Looks like this "number" column is not numeric at all, but rather
CHAR/VARCHAR.

Try
ORDER BY CONVERT(INT, thatColumn)

Or try making the column a numeric data type, if it holds numeric data.

Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

15 posts views Thread by David | last post: by
11 posts views Thread by Leon | last post: by
7 posts views Thread by Steve Crawford | last post: by
21 posts views Thread by yeti349 | last post: by
2 posts views Thread by adrian.chandler | last post: by
1 post views Thread by aarklon | last post: by
4 posts views Thread by Tony WONG | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.