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. SELECT and NOT IN a dynamic sequence

SELECT and NOT IN a dynamic sequence

Scheduled Pinned Locked Moved Database
databaseoraclequestion
5 Posts 2 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.
  • V Offline
    V Offline
    Vadim Tabakman
    wrote on last edited by
    #1

    Hi all, I need to be able to do a query for those values that are not in a particular field in a recordset. So lets say I have a table with a field (indexnum) which is a text string of a hex number. eg "00034F12". That number is incremented for each record that is added. Legacy code, so I don't know why it is done this way. What i need to do is query for all indexnum's that don't occur given a list of indexnums. Indexnums will be between 00000001 and 0x000FFFFF. These are not hardcoded, so at the time this code will be run, it maybe between 0034829F and 00349000. So some how I need something like : SELECT indexnum from tblData NOT IN ( SELECT ... [build up a temp table or something or a sequence of number from the starting and ending nummbers I give it] ) Can this be done somehow? I need it to work on DB's like Oracle and MS Access, and I don't think Access supports stored procedure (although I don't know much about these). Thanx If there's one thing I've learned, it's that life is one crushing defeat after another until you just wish Flanders was dead. - Homer Simpson

    M 1 Reply Last reply
    0
    • V Vadim Tabakman

      Hi all, I need to be able to do a query for those values that are not in a particular field in a recordset. So lets say I have a table with a field (indexnum) which is a text string of a hex number. eg "00034F12". That number is incremented for each record that is added. Legacy code, so I don't know why it is done this way. What i need to do is query for all indexnum's that don't occur given a list of indexnums. Indexnums will be between 00000001 and 0x000FFFFF. These are not hardcoded, so at the time this code will be run, it maybe between 0034829F and 00349000. So some how I need something like : SELECT indexnum from tblData NOT IN ( SELECT ... [build up a temp table or something or a sequence of number from the starting and ending nummbers I give it] ) Can this be done somehow? I need it to work on DB's like Oracle and MS Access, and I don't think Access supports stored procedure (although I don't know much about these). Thanx If there's one thing I've learned, it's that life is one crushing defeat after another until you just wish Flanders was dead. - Homer Simpson

      M Offline
      M Offline
      Mike Ellison
      wrote on last edited by
      #2

      What about a simple WHERE clause on indexnum?

      select indexnum
      from tblData
      where not (indexnum between @lowerBound and @higherBound)

      or maybe

      select indexnum
      from tblData
      where not (indexnum >= @lowerBound and indexnum <= @higherBound)

      V 1 Reply Last reply
      0
      • M Mike Ellison

        What about a simple WHERE clause on indexnum?

        select indexnum
        from tblData
        where not (indexnum between @lowerBound and @higherBound)

        or maybe

        select indexnum
        from tblData
        where not (indexnum >= @lowerBound and indexnum <= @higherBound)

        V Offline
        V Offline
        Vadim Tabakman
        wrote on last edited by
        #3

        This is me being lazy and not trying it, but asking a question first :) Given that indexnum is a text string, will this comparison work? For example : "00000007" "00000008" "0000000C" if we ran the sql query for "00000007" to "0000000C", would it return : "00000009" "0000000A" "0000000B" ???? I didn't think the database would be so smart as to count in hex using text strings. If there's one thing I've learned, it's that life is one crushing defeat after another until you just wish Flanders was dead. - Homer Simpson

        M 1 Reply Last reply
        0
        • V Vadim Tabakman

          This is me being lazy and not trying it, but asking a question first :) Given that indexnum is a text string, will this comparison work? For example : "00000007" "00000008" "0000000C" if we ran the sql query for "00000007" to "0000000C", would it return : "00000009" "0000000A" "0000000B" ???? I didn't think the database would be so smart as to count in hex using text strings. If there's one thing I've learned, it's that life is one crushing defeat after another until you just wish Flanders was dead. - Homer Simpson

          M Offline
          M Offline
          Mike Ellison
          wrote on last edited by
          #4

          Well, if your being lazy means more work for me, then I one-up your laziness with some of my own :) Try it out and see what you get. I think most databases consider "8,9,A,B,C" an ascending text sort.

          V 1 Reply Last reply
          0
          • M Mike Ellison

            Well, if your being lazy means more work for me, then I one-up your laziness with some of my own :) Try it out and see what you get. I think most databases consider "8,9,A,B,C" an ascending text sort.

            V Offline
            V Offline
            Vadim Tabakman
            wrote on last edited by
            #5

            Well touche. I respect your lazyness and bow down to it. I've been out-slothed. I will therefore try this out :) hehe Thanx Mike. If there's one thing I've learned, it's that life is one crushing defeat after another until you just wish Flanders was dead. - Homer Simpson

            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