• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 318
  • Last Modified:

referencing function in another database

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
tinman1412
Asked:
tinman1412
1 Solution
 
curtis591Commented:
select database.dbo.function(parameters) should do it for you.
0
 
AdiCohnCommented:
 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

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now