I can do with a temp table which just stores them...
Thanks,
Aash.
Main Topics
Browse All TopicsHi All,
I have two files in my tables which are of data type varchar in which IP Address are stored.
For e.g
IPFrom IPTo
89.28.184.0 89.28.184.21
I need to write a procedure to check if a given ip address falls between the range of these ip address and return true or false.
For e.g
If I pass the ip address 89.28.184.10 it should return true as the ip address falls between the from and to range of my table columns.
Hope this makes sense.
Thanks in advance.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
use the following function to convert the ip to integer
CREATE FUNCTION dbo.ipStringToInt
(
@ip CHAR(15)
)
RETURNS INT
AS
BEGIN
DECLARE @rv INT,
@o1 INT,
@o2 INT,
@o3 INT,
@o4 INT,
@base INT
SELECT
@o1 = CONVERT(INT, PARSENAME(@ip, 4)),
@o2 = CONVERT(INT, PARSENAME(@ip, 3)),
@o3 = CONVERT(INT, PARSENAME(@ip, 2)),
@o4 = CONVERT(INT, PARSENAME(@ip, 1))
IF (@o1 BETWEEN 0 AND 255)
AND (@o2 BETWEEN 0 AND 255)
AND (@o3 BETWEEN 0 AND 255)
AND (@o4 BETWEEN 0 AND 255)
BEGIN
SELECT @base = CASE
WHEN @o1 < 128 THEN
(@o1 * 16777216)
ELSE
-(256 - @o1) * 16777216
END
SET @rv = @base +
(@o2 * 65536) +
(@o3 * 256) +
(@o4)
END
ELSE
SET @rv = -1
RETURN @rv
END
yes i did and i have created the function. I pass the function and i am working on how to check if the given values falls between the from and to values of the ip address as thats the end result i want to get to
For e.g
IPFrom IPTo
89.28.184.0 89.28.184.21
I need to write a procedure to check if a given ip address falls between the range of these ip address and return true or false.
For e.g
If I pass the ip address 89.28.184.10 it should return true as the ip address falls between the from and to range of my table columns.
Thanks,
Aash
Business Accounts
Answer for Membership
by: matthewspatrickPosted on 2009-11-03 at 08:01:06ID: 25730266
Hello matrix_aash,
Is there any chance that you can get the four parts of the IP addresses stored in different tables? If so, that
would make the comparison you are proposing very, very easy :)
Regards,
Patrick