-
CREATE FUNCTION IP2INT( @ip nvarchar( 15 ) ) RETURNS bigint AS
-
BEGIN
-
DECLARE @number bigint
-
SET @number = 0
-
SELECT @number = @number +
-
LEFT ( @ip, CHARINDEX( '.', @ip + '.' ) -1 ) * t,
-
@ip = STUFF(@ip, 1, CHARINDEX( '.', @ip + '.' ), '' )
-
FROM
-
(
-
SELECT t = CAST( 16777216 AS bigint)
-
UNION ALL SELECT 65536
-
UNION ALL SELECT 256
-
UNION ALL SELECT 1
-
) AS T
-
RETURN (@number)
-
END
-
GO
-
DECLARE @IPTable TABLE (ip nvarchar( 15 ) )
-
INSERT INTO @IPTable VALUES ( N'172.16.57.103' )
-
INSERT INTO @IPTable VALUES ( N'172.16.58.103' )
-
INSERT INTO @IPTable VALUES ( N'172.16.59.103' )
-
INSERT INTO @IPTable VALUES ( N'172.16.60.103' )
-
INSERT INTO @IPTable VALUES ( N'172.16.61.103' )
-
INSERT INTO @IPTable VALUES ( N'172.16.62.103' )
-
SELECT ip
-
FROM @IPTable
-
WHERE dbo.IP2INT(ip)
-
BETWEEN dbo.IP2INT( '172.16.58.1' ) AND dbo.IP2INT( '172.16.60.1' )