Solved

referencing function in another database

Posted on 2002-06-17
2
303 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
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.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

717 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