Solved

referencing function in another database

Posted on 2002-06-17
2
265 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

762 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

18 Experts available now in Live!

Get 1:1 Help Now