Home All Groups Group Topic Archive Search About

Recognizing a function name without the Database and Owner

Author
3 Aug 2006 12:23 PM
rmcompute
I created a function as:  Create Function u_fnSRWorkDayCalc
And then used in a stored procedure, however, the only way I could get the
stored procedure to recognize it was to code it with the Database and Owner:
SvcReports.dbo.u_fnSRWorkDayCalc.  I would like to port the stored procedure
to 15 other databases and would like to keep the same program without going
in and changing SvcReports (the database name) for each stored procedure.  Is
there a way to create a function which does not need to be referenced like
this ?  I tried Create Function Public etc, but that didn't work.

Author
3 Aug 2006 12:34 PM
Dan Guzman
The owner (a.k.a. schema) is required by the SQL parser for function
references.  However, the database name qualifier is optional as long as the
stored procedures and function reside in the same database.  If the objects
are in different databases, 3-part names are needed to use the function.

--
Hope this helps.

Dan Guzman
SQL Server MVP

Show quote
"rmcompute" <rmcomp***@discussions.microsoft.com> wrote in message
news:2AC2D48C-3324-48A0-A220-EF1965344590@microsoft.com...
>I created a function as:  Create Function u_fnSRWorkDayCalc
> And then used in a stored procedure, however, the only way I could get the
> stored procedure to recognize it was to code it with the Database and
> Owner:
> SvcReports.dbo.u_fnSRWorkDayCalc.  I would like to port the stored
> procedure
> to 15 other databases and would like to keep the same program without
> going
> in and changing SvcReports (the database name) for each stored procedure.
> Is
> there a way to create a function which does not need to be referenced like
> this ?  I tried Create Function Public etc, but that didn't work.
>
>
>
Author
3 Aug 2006 1:00 PM
Omnibuzz
You can do without the database name if the function resides in the same
database, but you need the owner name for a scalar function. You don't need
the owner name either for a table valued function though.


--
-Omnibuzz (The SQL GC)

http://omnibuzz-sql.blogspot.com/
Author
3 Aug 2006 2:26 PM
Tracy McKibben
rmcompute wrote:
> I created a function as:  Create Function u_fnSRWorkDayCalc
> And then used in a stored procedure, however, the only way I could get the
> stored procedure to recognize it was to code it with the Database and Owner:
> SvcReports.dbo.u_fnSRWorkDayCalc.  I would like to port the stored procedure
> to 15 other databases and would like to keep the same program without going
> in and changing SvcReports (the database name) for each stored procedure.  Is
> there a way to create a function which does not need to be referenced like
> this ?  I tried Create Function Public etc, but that didn't work.
>
>
>

As others have replied, the database name is optional, but the owner is
required.  Also, using schema-qualified object names is a GOOD habit to
learn, it can help avoid some very frustrating debug situations.


--
Tracy McKibben
MCDBA
http://www.realsqlguy.com

AddThis Social Bookmark Button