Friday, February 10, 2012

calling user-defined functions in another DB

I have a number of databases that require a set of common functions. I'd like to place all those functions in a central DB. I'm having trouble calling them using the syntax FunctionDB.GetParamLength() for example, which works within the FunctionDB database.

Any ideas/suggestions? I really don't want to maintain seperate copies of the functions across 5+ databases.

You have to qualify the function name with owner name, as in

FunctionDB.dbo.GetParamLength()

|||I've tried that, unfortunately no luck.|||Should work for you like this here:

USE Master

GO

CREATE FUNCTION dbo.DisplaySomething()

RETURNS VARCHAR(10)

AS

BEGIN

RETURN('Something')

END

GO

USE AdventureWorks

GO

SELECT master.dbo.DisplaySomething()

USE Master

GO

DROP FUNCTION dbo.DisplaySomething

Is the database case sensitive ? Then you have use the right case sensitive name. Is the owner of the function dbo ? Otherwise you have to name the original owner.


HTH, jens Suessmeyer.

http://www.sqlserver2005.de

|||There was an error within the function I was calling which confused me, thanks for putting me on the right track :)

No comments:

Post a Comment