Results 1 to 4 of 4
  1. #1
    Join Date
    May 2007

    Unanswered: Comparing range within strings.

    Hello, my first post

    I'm currently working on a project that involves IP checking, here's my scenario:

    A user enters an IP address of let's say, I want to somehow be able to check and see if this IP address is in between column A (It's called ip) which consists the IP data of and column B (It's called EndingIp) which has the IP data, so generally speaking I'm checking for the 3rd and 4th spots within the IP address and I'm trying to see if it's between the IP's in column A and B.

    The thing is these are all strings, so how do I approch a stiuation like that within SQL?

    Btw, I attached a picture of the table to be more clear.

    Thanks in advance for the advice...
    Attached Thumbnails Attached Thumbnails ipcheck.JPG  

  2. #2
    Join Date
    Sep 2004
    Quote Originally Posted by birko19
    ... I'm trying to see if it's between the IP's in column A and B.
    If I understand it well, you could just check with
    This will only work if e.g. is written as, i.e., if all four entries have 3 digits. In that case "alphabetic" order is the ordering you want.
    It's probably more difficult to convert val, A and B to this format, so you will have to extract the four parts with some scalar function, recompose (either as string, in the 4x3 digit form, or as an integer: field1 x 256^3 + field2 x 256^2 + field3 x 256 + field4) and then have the BETWEEN condition.
    Available scalar functions for this purpose may differ from system to system, so I won't go into details here.
    --_Peter Vanroose,
    __IBM Certified Database Administrator, DB2 9 for z/OS
    __IBM Certified Application Developer
    __ABIS Training and Consulting

  3. #3
    Join Date
    Apr 2002
    Toronto, Canada
    if you would kindly mention which database you're using, birko, i'll move this thread to the approproate forum where you may get more specific answers | @rudydotca
    Buy my SitePoint book: Simply SQL

  4. #4
    Join Date
    May 2007
    I'm sorry if I posted this in the wrong forum, anyways I'm using SQL 2000 server and I kind of fixed the problem of comparing within the range logically, here's what I have in a stored procedure which seems to work for IP range checking:

    -- This procedure checks for the IP range.
    @ipAdd varchar(50) as
    	when (@ipAdd <= '' and @ipAdd >= '')
    	    then 'IP EXISTS'
    Of course my next step is to get the values from the columns and do the comparring with them, so I'm off to do that

    Just a background about the project, we have an ASP.NET web application coded in C# and there's a part where the user has to enter an IP address, we have to see whether the IP exists within the database or not and that's where the range check comes in since some customers have a bunch of IP addresses that range from let's say up to, so we want to check within the range of the IP addresses in out database, it's a long project but hopfully it can be done soon.

    Thank you guys

Posting Permissions

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