Pr0no
Pr0no

Reputation: 4099

Why is my function name ambiguous? It is not imho?

Please consider the following function and function call:

create function [dbo].[GetCidrIpRange2](@CidrIp varchar(15))
returns @result table
(
    LowRange    varchar(15) not null,
    HighRange   varchar(15) not null,
    AddressQty  bigint not null
)
as
begin
    declare @Base       bigint  = cast(4294967295 as bigint)
    declare @Mask       int     = cast(substring(@CidrIp, patindex('%/%' , @CidrIP) + 1, 2) as int)
    declare @Power      bigint  = Power(2.0, 32.0 - @Mask) - 1
    declare @LowRange   bigint  = dbo.[IPAddressToInteger](left(@CidrIp, patindex('%/%' , @CidrIp) - 1)) & (@Base ^ @Power)
    declare @HighRange  bigint  = @LowRange + @Power

    insert @result
    select
         LowRange   = @LowRange
        ,HighRange  = @HighRange
        ,AddressQty = convert(bigint, power(2.0, (32.0 - @Mask)))
    return
end

select [dbo].[GetCidrIpRange2]('195.65.254.11/2');

I get the following error:

Cannot find either column "dbo" or the user-defined function or aggregate "dbo.GetCidrIpRange2", or the name is ambiguous.

The name is unique, and when I run only the function, it created the function properly in the session:

Command(s) completed successfully.

What am I doing wrong?

Upvotes: 1

Views: 706

Answers (1)

Zohar Peled
Zohar Peled

Reputation: 82474

You are missing a FROM:

SELECT * FROM [dbo].[GetCidrIpRange2]('195.65.254.11/2');

Upvotes: 3

Related Questions