Sorting numbers..

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • berry
    New Member
    • May 2007
    • 46

    Sorting numbers..

    Hi guys..

    I facing a troble here. Please help me.
    I want to sort my database in ascending number.
    Such as a series: 10, 100, 20, 30, 27.
    Answer will be: 10, 100, 20, 27, 30.
    But the answer i want is: 10, 20, 30, 27, 100.

    How should i write the code??
    Below is my code. Please take a look and correct for me.

    Thank you very much..

    Code:
    Adodc.RecordSource = "select * from table order by totalTime;"
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Originally posted by berry
    ...
    Code:
    Adodc.RecordSource = "select * from table order by totalTime;"
    That SQL looks fine. Why, do you have a problem with it?

    Oops! Sorry, had to go back and re-read.

    The problem is fairly obvious. They are being sorted as strings, not numbers. The field type must be Text. If it is going to hold numbers, change it to a numeric data type.

    (If you think about it, the response you are getting is sorted into perfect alphabetic sequence).

    Comment

    • coolminded
      New Member
      • Mar 2007
      • 137

      #3
      Originally posted by berry
      Hi guys..

      I facing a troble here. Please help me.
      I want to sort my database in ascending number.
      Such as a series: 10, 100, 20, 30, 27.
      Answer will be: 10, 100, 20, 27, 30.
      But the answer i want is: 10, 20, 30, 27, 100.

      How should i write the code??
      Below is my code. Please take a look and correct for me.

      Thank you very much..

      Code:
      Adodc.RecordSource = "select * from table order by totalTime;"
      you can use the function
      to_number(field _name,999999)
      it will give the solution u want
      eg:
      select to_number(field _name,999999) from table_name

      plz do reply if this works or not
      with regards

      Comment

      • berry
        New Member
        • May 2007
        • 46

        #4
        Originally posted by coolminded
        you can use the function
        to_number(field _name,999999)
        it will give the solution u want
        eg:
        select to_number(field _name,999999) from table_name

        plz do reply if this works or not
        with regards
        I had tried the function u taught. But it can't work.
        The error shows is "FUNCTION TableName.to_nu mber does not exist".
        Anyway, thanks for your help.

        Comment

        • berry
          New Member
          • May 2007
          • 46

          #5
          Originally posted by Killer42
          That SQL looks fine. Why, do you have a problem with it?

          Oops! Sorry, had to go back and re-read.

          The problem is fairly obvious. They are being sorted as strings, not numbers. The field type must be Text. If it is going to hold numbers, change it to a numeric data type.

          (If you think about it, the response you are getting is sorted into perfect alphabetic sequence).

          Thanks Killer42. I get it d. But I don't know what type I should assign for the hour and date that user key in. Please help me.

          Comment

          • Killer42
            Recognized Expert Expert
            • Oct 2006
            • 8429

            #6
            Originally posted by berry
            Thanks Killer42. I get it d. But I don't know what type I should assign for the hour and date that user key in. Please help me.
            What data are you actually storing in the fields? If it is a number, I would set the field type to Number. To determine the size, select the Field Size entry field, and hit F1 for information on which size can hold what values.

            Comment

            • Killer42
              Recognized Expert Expert
              • Oct 2006
              • 8429

              #7
              Originally posted by berry
              I had tried the function u taught. But it can't work.
              The error shows is "FUNCTION TableName.to_nu mber does not exist".
              I'm not familiar with ToNumber, but I expect the Val() function should work.

              By the way, remember TheScripts also has an Access forum where you can probably get much better answers on any Access-related questions.

              Comment

              • berry
                New Member
                • May 2007
                • 46

                #8
                Originally posted by Killer42
                What data are you actually storing in the fields? If it is a number, I would set the field type to Number. To determine the size, select the Field Size entry field, and hit F1 for information on which size can hold what values.
                How if I want to store the date in format: 4 June 2007. There are number and character.

                Comment

                Working...