Solved

referencing function in another database

Posted on 2002-06-17
2
274 Views
Last Modified: 2008-03-06
I have a user defined function in one database.  Within query analyer, I would call the function with this syntax dbo.myfunction(). my function is in the first database.  I'm writing a stored procedure and want to call this function within an instance of another database.  I can't seem to reference my function outside of the first database.

Thanks
0
Comment
Question by:tinman1412
2 Comments
 
LVL 6

Accepted Solution

by:
curtis591 earned 50 total points
ID: 7083983
select database.dbo.function(parameters) should do it for you.
0
 

Expert Comment

by:AdiCohn
ID: 7084024
 You need to specify the database's name.  DatabaseName.FunctionOwner.FunctionName.  Here is a small example:

USE pubs
GO

--Creating a small function in pubs database
create function MyTest() returns int
as
begin
return (1)
end

GO

USE northwind
GO

--Creating a stored procedure in the northwind database
create procedure MyStored
as
declare @t int
--Notice the way that I specify the location of the
--function.
set @t = pubs.dbo.MyTest()
print @t
return

GO

Exec MyStored
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now