Scalar-valued Functions [dbo].[ip2hex]
Properties
PropertyValue
ANSI Nulls OnYes
Quoted Identifier OnYes
Parameters
NameData TypeMax Length (Bytes)
@ipaddr_strchar(15)15
Permissions
TypeActionOwning Principal
GrantExecuteca_itrm_group
GrantExecuteca_itrm_group_ams
SQL Script
/* ************************** 11535 begin **************/



CREATE FUNCTION ip2hex(@ipaddr_str char(15) )  
RETURNS binary(4)
AS  
BEGIN
    declare @ipaddr_hex binary(4)
    declare @ipaddr float, @ipbyte int, @temp char(25), @ch char(1), @ipaddr_int int

    if (@ipaddr_str = NULL)
    begin
        select @ipaddr_hex = NULL
        return @ipaddr_hex
    end
    select @ipaddr = 0, @ipbyte = 0, @temp = ltrim(@ipaddr_str)

    while  @ipaddr >= 0
    begin
        select @ch = substring( @temp, 1, 1 )
        if @ch = '.'
        begin
            select @ipaddr = (@ipaddr + @ipbyte) * 256
            select @ipbyte = 0
        end
        else if @ch between '0' and '9'
            select @ipbyte = (@ipbyte * 10) + (ASCII( @ch ) - ASCII( '0' ))
        else
        begin
            select @ipaddr = @ipaddr + @ipbyte
            if @ipaddr > 2147483647.0
            begin
                select @ipaddr = - (4294967295.0 - @ipaddr + 1)
            end
            select @ipaddr_int = convert(int, @ipaddr)
            select @ipaddr_hex = convert(binary(4), @ipaddr_int)
            return @ipaddr_hex
        end
        select @temp = stuff( @temp, 1, 1, ' ' )
        select @temp = ltrim(@temp)
    end

return @ipaddr_hex
END
GO
GRANT EXECUTE ON  [dbo].[ip2hex] TO [ca_itrm_group]
GRANT EXECUTE ON  [dbo].[ip2hex] TO [ca_itrm_group_ams]
GO
Uses
Used By