有没有更好的方法从链接服务器调用 UDF?
我从以前的同行那里继承了一个存储过程,该过程使用来自链接服务器的用户定义函数。调用服务器使用sql server 2008,链接服务器使用具有2000兼容性的sql server 2005。
由于不允许从链接服务器调用 UDF,因此他所做的就是在调用服务器上复制该函数。该函数采用一个参数并返回一个标量 int 值。它用在存储过程中的选择列之一中:
select
columnA,
columnB,
fn_Function(columnC) as columnC_Alias
from TableD
这一切都工作正常,但如果链接服务器上的函数被不知道调用服务器上的这种重复的人更新,则可能会出现问题,从而导致两个版本之间不一致。
我知道在链接服务器上创建SP来封装功能的方法,但在这里不太适用。
有更好的方法吗?
I was inherited a stored procedure from my former counterpart that uses a user-defined function from a linked server. The calling server uses sql server 2008 and the linked server uses sql server 2005 with 2000 compatibility.
Since calling UDFs from a linked server is not permitted, what he did was to duplicate the function on the calling server. The function takes one parameter and returns a scalar int value. It is used in one of the select columns in the stored procedure:
select
columnA,
columnB,
fn_Function(columnC) as columnC_Alias
from TableD
This all works fine, but problem could arise if the function on the linked server gets updated by someone who's unaware of this duplication on the calling server creating inconsistencies between the two versions.
I am aware of the method of creating an SP on the linked server to encapsulate the function, but it doesn't quite work here.
Is there a better approach?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只要您传递的参数值取决于表,您就可以将表和 UDF 包装在视图中,并从 SP 内引用该视图:
As long as the value of the parameter that you are passing is dependent on the table you could wrap both the table and the UDF in a view and refer to the view from within your SP: