title: SQL Server: How to call a user-defined function (UDF) on linked server?
body: <p>i'm trying to call a User-Defined Function (UDF) on a linked server:</p>
  
  <pre><code>CREATE FUNCTION [dbo].[UserGroupMembershipNames](@UserGUID uniqueidentifier)  
  RETURNS VARCHAR(8000)
  AS
  BEGIN
      RETURN ASILIVE.ReportManager.dbo.UserGroupMembershipNames(@UserGUID)
  END
  </code></pre>
  
  <p>This doesn't work, as documented in <a href="http://support.microsoft.com/kb/319138" rel="noreferrer">PRB: User-Defined Function Call in Four-Part Linked Server Query Fails with Error Message 170</a>. They also give a workaround:</p>
  
  <blockquote>
    <p>For example, instead of the following query  </p>
  
  <pre><code>Select * from Linked_Server.northwind.dbo.square_value(10)
  </code></pre>
    
    <p>run a query with the Openquery function:</p>
  
  <pre><code>Select * from Openquery(Linked_Server,'select northwind.dbo.square_ value(10)')
  </code></pre>
    
    <p>If the user-defined function takes variable or scalar parameters, you can use the sp_executesql stored procedure to avoid this behavior. For example:</p>
  
  <pre><code>exec Linked_Server.northwind.dbo.sp_executesql N'SELECT northwind.dbo.square_value(@input)',N'@input int',@input=10
  </code></pre>
  </blockquote>
  
  <p>How would i apply this workaround to my situation, and the situation of <a href="http://www.daniweb.com/forums/thread51696.html" rel="noreferrer">this guy</a>?</p>
  
  <p>In other words:</p>
  
  <p><strong>How to call a UDF on a linked server?</strong></p>