I created a user-defined scalar function in SQL Server Management Studio that takes two dates and calculates the minimum of the two.
When I tried to use the function, I was initially getting an error that said "Cannot find either column "dbo" or the user-defined function or aggregate "dbo.MinDate", or the name is ambiguous."
I finally got it to work by executing the function like:
"CREATE FUNCTION dbo.MinDate..."
(I was running into trouble because I hadn't added the "dbo")
And I was using the function without any problem in a query that I saved.
I shut down SQL Server and then created a new instance a couple days later in Management Studio.
Now, if I open that saved query, it can run SELECT dbo.MinDate('2014-03-14 17:54:32.000','2014-03-14 17:06:01.000') without any problems, but if I open up a new query, and put in the SELECT statement above, I'm getting the error "Cannot find either column "dbo" or the user-defined function or aggregate "dbo.MinDate", or the name is ambiguous." again.
So, do I have to "CREATE" the function every time? Except if it's in a query I've already used before, then it has the capacity to remember the function. It doesn't make sense to me that it would work this way. Is that true, and is there a way to load a function more permanently? For the end result, I'm trying to use these functions with SQLCommands in VB.NET and C# and that is ultimately where I'm running into the problem/need a solution.
Thank you.