And with some error checking
alter function dbo.ConvertIp2Num(@ip varchar(15))
returns bigint
as
begin
returncase
when @ip like '%[^0-9.]%' then NULL
when @ip like '%.%.%.%.%' then null
when @ip like '%..%' then null
when @ip like '%[0-9][0-9][0-9][0-9]%' then null
else 16777216.0 * parsename(@ip, 4)
+ 65536 * parsename(@ip, 3)
+ 256 * parsename(@ip, 2)
+ 1 * parsename(@ip, 1)
end
end
Or see this topic from 2006
http://www.sqlservercentral.com/Forums/Topic302100-145-1.aspx
N 56°04'39.16"
E 12°55'05.25"