|
-
Aug 3rd, 2009, 09:43 AM
#1
Thread Starter
Frenzied Member
MSSQL using UDF across servers
Hey all,
I am running into an issue trying to call a user defined function across servers. Then error I am getting is The multi-part identifier "myserver.database.schema.functionname" could not be bound.
This is the code I am trying to use:
Code:
declare @storeNo INT
declare @vendorID INT
declare @payAgreed BIT
select @sql = N'select @store = IST.Store_No, @vendor = IVS.Vendor_ID
FROM POHeader H
inner join ' + @DBString + '[Store] IST on H.BusinessUnit = IST.BusinessUnit_ID
inner join ' + @DBString + '[Vendor] IVS on IVS.Store_No = IST.Store_No'
exec sp_executesql @sql
, N'@store INT OUTPUT,@vendor int OUTPUT'
, @store = @storeNO OUTPUT, @vendor = @vendorID OUTPUT
select @sql = N'SET @payAgreedCost = ' + @DBString + '[fn_IsPayByAgreedCostStoreVendor(@storeNo, @vendorID, getdate())]'
exec sp_executesql @sql
, N'@payAgreedCost BIT OUTPUT'
, @payAgreedCost = @payAgreed OUTPUT
any ideas on how to work around this?
Thanks!
-
Aug 3rd, 2009, 12:40 PM
#2
Re: MSSQL using UDF across servers
you need to have linked servers on, and the initiating server needs to know about the destination server. Once you have that set up, you should be able to access the function using: linkservername.databasename.dbo.functionname
-tg
-
Aug 3rd, 2009, 12:46 PM
#3
Thread Starter
Frenzied Member
Re: MSSQL using UDF across servers
The joins work fine across servers, do those not require linked server being turned on?
-
Aug 3rd, 2009, 12:54 PM
#4
Re: MSSQL using UDF across servers
then there's something missing from the multi identifier that isn't right. I know that in the past, I've had to use dbo. even when using UDFs from inside the same db.
So the question is, what is "@DBString" at the moment the call is made?
-tg
-
Aug 3rd, 2009, 01:00 PM
#5
Thread Starter
Frenzied Member
Re: MSSQL using UDF across servers
yeah the error message contains the full path
ServerName.DBName.dbo.Functionname
-
Aug 3rd, 2009, 02:47 PM
#6
Thread Starter
Frenzied Member
Re: MSSQL using UDF across servers
I moved the ] to the end of the function name and now I get a new error message:
Invalid column name 'servername'
-
Aug 3rd, 2009, 04:24 PM
#7
Re: MSSQL using UDF across servers
I didn't even see that initially... try taking the [ and ] off completely.
-tg
-
Aug 3rd, 2009, 04:46 PM
#8
Thread Starter
Frenzied Member
Re: MSSQL using UDF across servers
yeah that gives the same error... I have been asking around and did some poking around, everything points to wrapping a sp around the function then calling the sp. Gonna try that in the morning.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|