Scalar-valued Functions [dbo].[ip6Tohex]
Properties
PropertyValue
ANSI Nulls OnYes
Quoted Identifier OnYes
Parameters
NameData TypeMax Length (Bytes)
@ipaddr_strchar(64)64
Permissions
TypeActionOwning Principal
GrantExecuteca_itrm_group
GrantExecuteca_itrm_group_ams
SQL Script
CREATE FUNCTION [dbo].[ip6Tohex](@ipaddr_str char(64) )  
RETURNS binary(16)
AS  
BEGIN
    declare @ipaddr_hex binary(16)
    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

    if ( charindex(':',@ipaddr_str) >0 )
    begin
        -- must be an IPv6 address
        -- colon hexadecimal address
        set @ipaddr_hex = dbo.ip6ColTohex(@ipaddr_str);
        return @ipaddr_hex;
    end
    
    -- must be an IPv4 address

    if ( charindex('.',@ipaddr_str) >0 )
    begin
        select @ipaddr_hex = convert(binary(16), convert(bigint, dbo.ip2hex(@ipaddr_str)));
        return @ipaddr_hex
    end
    return NULL

END
GO
GRANT EXECUTE ON  [dbo].[ip6Tohex] TO [ca_itrm_group]
GRANT EXECUTE ON  [dbo].[ip6Tohex] TO [ca_itrm_group_ams]
GO
Uses