Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
4.20/5 (4 votes)
See more:
Can anybody help me with the problem that I am facing while calling functions using linked server, please explain via sample code.

Any help in this regard will be highly appreciated.
Posted

1 solution

User defined functions cannot be called on Linked Server.

To work around this problem, use the Openquery function instead of the four-part naming convention.

You need to create following function in your DB where Linked Server needs to call.

SQL
CREATE FUNCTION [dbo].Function_Name(@Parameter INT)

RETURNS VARCHAR(8000)

AS

BEGIN

DECLARE @word sysname

EXEC LinkedServer.DatabaseName.dbo.sp_executesql

N'SELECT DatabaseName.dbo.Function_Name(@Parameter)' --dynamic sql query to execute

,N'@Parameter int' --parameter definitions

,@Parameter=@word OUTPUT --assigning the caller procs local variable to the dynamic parameter

RETURN @word

END




For more details, kindly visit the link below.

http://developersmania.blogspot.com/2012/11/call-user-defined-function-on-linked.html[^]

I hope this helps you.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900