Pr0no Pr0no - 1 year ago 58
SQL Question

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
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
LowRange = @LowRange
,HighRange = @HighRange
,AddressQty = convert(bigint, power(2.0, (32.0 - @Mask)))

select [dbo].[GetCidrIpRange2]('');

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?

Answer Source

You are missing a FROM:

SELECT * FROM [dbo].[GetCidrIpRange2]('');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download