/** // * -- Convert a balanced IP address to a digital IP Address
/** // * -- Call example
Select DBO. f_ip2int ('192. 168.0.11 ')
Select DBO. f_ip2int ('12. 168.0.1 ')
--*/
Create Function [DBO]. [f_ip2int] (
@ IP char (15)
) Returns bigint
As
Begin
Declare @ Re bigint
Set @ Re = 0
Select @ Re = @ Re + Left (@ IP, charindex ('.', @ IP + '.')-1) * ID
, @ IP = stuff (@ IP, 1, charindex ('.', @ IP + '.'),'')
From (
Select id = cast (16777216 as bigint)
Join all select 65536
Join all select 256
Union all select 1)
Return (@ Re)
End
/** // * -- Convert a Digital IP address to a formatted IP Address
-- Producer build 2004.08 (reference please keep this information )--*/
/** // * -- Call example
Select DBO. f_int2ip (3232235531)
Select DBO. f_int2ip (212336641)
*/
Create Function [DBO]. [f_int2ip] (
@ IP bigint
) Returns varchar (15)
As
Begin
Declare @ Re varchar (15)
Set @ Re =''
Select @ Re = @ Re + '.' + Cast (@ IP/ID as varchar)
, @ IP = @ IP % ID
From (
Select id = cast (16777216 as bigint)
Join all select 65536
Join all select 256
Union all select 1)
Return (stuff (@ Re, 1,1 ,''))
End