Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. how to select numbers (integers) only?

how to select numbers (integers) only?

Scheduled Pinned Locked Moved Database
questioncomtutorialannouncement
7 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jassim Rahma
    wrote on last edited by
    #1

    Hi, I have employee_number field which has employee_numbers like this: 12 434 ABC345 QWR-567 I want to know how can I just select the numeric values to perform a MAX on it? so ABC345 and QWR-567 will not be considered in the SELECT

    Technology News @ www.JassimRahma.com

    L T M P 4 Replies Last reply
    0
    • J Jassim Rahma

      Hi, I have employee_number field which has employee_numbers like this: 12 434 ABC345 QWR-567 I want to know how can I just select the numeric values to perform a MAX on it? so ABC345 and QWR-567 will not be considered in the SELECT

      Technology News @ www.JassimRahma.com

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You could always try a regex to parse out only the numbers.

      1 Reply Last reply
      0
      • J Jassim Rahma

        Hi, I have employee_number field which has employee_numbers like this: 12 434 ABC345 QWR-567 I want to know how can I just select the numeric values to perform a MAX on it? so ABC345 and QWR-567 will not be considered in the SELECT

        Technology News @ www.JassimRahma.com

        T Offline
        T Offline
        thatraja
        wrote on last edited by
        #3

        Googled? Check this thread[^]

        thatraja

        Code converters | Education Needed | Improve EverythingNew

        1 Reply Last reply
        0
        • J Jassim Rahma

          Hi, I have employee_number field which has employee_numbers like this: 12 434 ABC345 QWR-567 I want to know how can I just select the numeric values to perform a MAX on it? so ABC345 and QWR-567 will not be considered in the SELECT

          Technology News @ www.JassimRahma.com

          M Offline
          M Offline
          Mycroft Holmes
          wrote on last edited by
          #4

          Some guidance on the database you are using would be useful. Take a look at the ISNUMERIC keyword in BOL.

          Never underestimate the power of human stupidity RAH

          1 Reply Last reply
          0
          • J Jassim Rahma

            Hi, I have employee_number field which has employee_numbers like this: 12 434 ABC345 QWR-567 I want to know how can I just select the numeric values to perform a MAX on it? so ABC345 and QWR-567 will not be considered in the SELECT

            Technology News @ www.JassimRahma.com

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #5

            WHERE id NOT LIKE '%[a-z]%' will eliminate any with alphabetic characters, that's a start, work from there.

            You'll never get very far if all you do is follow instructions.

            J 1 Reply Last reply
            0
            • P PIEBALDconsult

              WHERE id NOT LIKE '%[a-z]%' will eliminate any with alphabetic characters, that's a start, work from there.

              You'll never get very far if all you do is follow instructions.

              J Offline
              J Offline
              Jassim Rahma
              wrote on last edited by
              #6

              I tried this:

              SELECT employee_number FROM employees WHERE employee_number REGEXP ('[0-9]');

              it's working excellent and I getting these numbers 7, 8, 9, 11, 1.222, 12, 13, 9, 15, 9, 9, 9 BUT.... when I run:

              SELECT MAX(employee_number) FROM employees WHERE employee_number REGEXP ('[0-9]');

              I get 9 where i should get 15. why is that?

              Technology News @ www.JassimRahma.com

              P 1 Reply Last reply
              0
              • J Jassim Rahma

                I tried this:

                SELECT employee_number FROM employees WHERE employee_number REGEXP ('[0-9]');

                it's working excellent and I getting these numbers 7, 8, 9, 11, 1.222, 12, 13, 9, 15, 9, 9, 9 BUT.... when I run:

                SELECT MAX(employee_number) FROM employees WHERE employee_number REGEXP ('[0-9]');

                I get 9 where i should get 15. why is that?

                Technology News @ www.JassimRahma.com

                P Offline
                P Offline
                PIEBALDconsult
                wrote on last edited by
                #7

                Because they're strings; you'll need to convert to numeric fo rthe comparisons to work the way you want.

                You'll never get very far if all you do is follow instructions.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups