Unix Technical Forum

sql SORT order not working on numbers?

This is a discussion on sql SORT order not working on numbers? within the SQL Server forums, part of the Microsoft SQL Server category; --> Hello all... I'm using asp to get records from an access database, very similar to the way datagrid would ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 06:06 PM
Alpay Eno
 
Posts: n/a
Default 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



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 06:06 PM
Mark Schupp
 
Posts: n/a
Default Re: sql SORT order not working on numbers?

What is the data type of the column containing the number?

--
Mark Schupp
--
Head of Development
Integrity eLearning
Online Learning Solutions Provider
mschupp@ielearning.com
http://www.ielearning.com
714.637.9480 x17


"Alpay Eno" <eno@spamsux.com> wrote in message
news:MxfPa.5539$hY1.1399166@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
>
>
>



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 06:06 PM
Aaron Bertrand - MVP
 
Posts: n/a
Default Re: sql SORT order not working on numbers?

> 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.



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 03:11 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com