Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 calling a udf in another database

Author  Topic 

ts_abbott@hotmail.com
Starting Member

36 Posts

Posted - 2004-11-29 : 11:59:54
I need to call a udf in another database - is this possible?

This works...

USE PostCode
SELECT dbo.CalcDistance('AB12 3CD, 'EF4 5GH')

This doesn't...

USE MyDB
SELECT PostCode..CalcDistance('AB12 3CD, 'EF4 5GH')

X002548
Not Just a Number

15586 Posts

Posted - 2004-11-29 : 12:08:29
[code]
USE Northwind
GO

SET NOCOUNT ON
GO

CREATE FUNCTION myUDF99 (@x int)
RETURNS int
AS
BEGIN
DECLARE @y int
SELECT @y = @x * 2
RETURN @y
END
GO

SELECT dbo.myUDF99(2)

USE Pubs
GO

SELECT Northwind.dbo.myUDF99(2)
GO

USE Northwind
GO

SET NOCOUNT OFF
DROP FUNCTION myUDF99
GO

[/code]


Brett

8-)
Go to Top of Page

ts_abbott@hotmail.com
Starting Member

36 Posts

Posted - 2004-11-29 : 12:27:28
thanks Brett, I thought you needed two dots (i.e. Northwind..) when referencing different databases. cheers.
Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2004-12-01 : 02:27:22
you need to include the owner name when referencing objects outside the current database.

database.owner.object, else it's database..object wherein sql assumes it's owner is dbo.

--------------------
keeping it simple...
Go to Top of Page
   

- Advertisement -