Conversion help
-
I want to take an IP address e.g. 111.222.333.444 and convert it to either a float or an unsigned datatype. Thanks,
-
I want to take an IP address e.g. 111.222.333.444 and convert it to either a float or an unsigned datatype. Thanks,
Why? An IP address is really a string of numbers - not a number. Removing the dots won't help because you really don't know where to put them back. I suppose you could always store it as four numbers, but it still doesn't gain you much.
Deja View - the feeling that you've seen this post before.
-
Why? An IP address is really a string of numbers - not a number. Removing the dots won't help because you really don't know where to put them back. I suppose you could always store it as four numbers, but it still doesn't gain you much.
Deja View - the feeling that you've seen this post before.
The reason is for faster search indexing. I found this after I posted; Create FUNCTION [dbo].[Dot2LongIP]( @IP VarChar(15) ) RETURNS BigInt AS BEGIN DECLARE @ipA BigInt, @ipB Int, @ipC Int, @ipD Int, @ipI BigInt SELECT @ipA = LEFT(@ip, PATINDEX('%.%', @ip) - 1 ) SELECT @ip = RIGHT(@ip, LEN(@ip) - LEN(@ipA) - 1 ) SELECT @ipB = LEFT(@ip, PATINDEX('%.%', @ip) - 1 ) SELECT @ip = RIGHT(@ip, LEN(@ip) - LEN(@ipB) - 1 ) SELECT @ipC = LEFT(@ip, PATINDEX('%.%', @ip) - 1 ) SELECT @ip = RIGHT(@ip, LEN(@ip) - LEN(@ipC) - 1 ) SELECT @ipD = @ip RETURN ( @ipA * 256*256*256 ) + ( @ipB * 256*256 ) + ( @ipC * 256 ) + @ipD END RETURN @ipI END This does speed it up and seems to meet my needs. Thanks,