sql SORT order not working on numbers?

Ask a Question related to ASP Database, Design and Development.

  1. #1

    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



    Alpay Eno Guest

  2. Similar Questions and Discussions

    1. ORDER BY (numbers and letters)
      I've got a table of data that I want to sort by lot number. The lots are in the form of 1A, 1B, 2A and so on. Obviously, this is a text field. So...
    2. PHP Sort order definitions
      I couldn't seem to find this in the docs or the web doing a quick search... When doing a sort($aRay, $flag) what is the definition for how the...
    3. Natural order sort
      I've written a natural order comparison funtion for the String class. This was based on Martin Pool's "Natural Order String Comparison" which was...
    4. Sort order
      Hi, I've a table with some rows. With 'select * from tab order by sp1' I've got the following: sp1 --- a1 a2
    5. how to sort numbers in varchar2
      I have a varchar2 column which stores characters as well as numbers in string such as '12345'. I would like to sort the column so that it orders...
  3. #2

    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
    [email]mschupp@ielearning.com[/email]
    [url]http://www.ielearning.com[/url]
    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
    >
    >
    >

    Mark Schupp Guest

  4. #3

    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.



    Aaron Bertrand - MVP Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139