I created a sql function to verify that a year is a valid number. Now I am creating a function to make sure if param1 is non-null, param2 must also be non-null.
For whatever reason the dbo.fun_chk_year works great, but dbo.fun_chk_req throws:
Cannot find either column 'dbo' or the user-defined function or aggregate 'dbo.fun_chk_req' or the name is ambiguous
----EDITED-----
Sorry guys, I tried to omit some of the code that seemed irrelevant to the problem and made changes I shouldn't have in an attempt to simplify the question. Here's a better explanation:
This is run first (it's in a separate query document). It executes seemingly without any issues.
CREATE FUNCTION dbo.fun_chk_year (@year smallint)
RETURNS tinyint
AS
BEGIN
IF (@year>1000 AND @year<=9999)
return 1;
return 0;
END
GO
CREATE FUNCTION [dbo].[fun_chk_req](@v1 sql_variant,@v2 sql_variant)
RETURNS tinyint
AS
BEGIN
IF (@v1 IS NULL OR (@v2 IS NOT NULL AND @v1 IS NOT NULL))
return 1;
return 0;
END
GO
This is run second. This is where I get the error.
CREATE TABLE [dbo].[repair](
[ID] [int] IDENTITY(1,1) NOT NULL,
[year] [smallint] NULL
CONSTRAINT year_cnstr CHECK (dbo.fun_chk_year(year)=1),
[year_completed] [smallint] NULL
CONSTRAINT comp_cnstr CHECK (dbo.fun_chk_year(year_completed)=1),
CONSTRAINT yr_and_comp_cnstr CHECK ([dbo].[fun_chk_req](year_completed,year)=1),
PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO