【问题标题】:Remote function calls not allowed within a function函数内不允许远程函数调用
【发布时间】:2013-02-16 15:10:09
【问题描述】:

标量值函数在调用远程函数后失败。有没有办法调用远程服务器功能?

这是代码

ALTER FUNCTION [dbo].[fnGetCatalogNumber] 
(
    -- Add the parameters for the function here
    @ProductID int
)
RETURNS varchar(20) 
AS
BEGIN
     -- Declare the return variable here
      DECLARE @CatalogNumber varchar(20), @catalog_data varchar(20)


    -- Add the T-SQL statements to compute the return value here
    --Exec Dev01.Product_Core.dbo.usp_get_CatalogNumber @ProductId = @ProductID 
     ,@CatalogNumber = @catalog_data output

    -- Return the result of the function
    RETURN @CatalogNumber

END

【问题讨论】:

  • 如果可能的话,我会反其道而行之。将逻辑放入函数中,从存储的proc中调用函数。
  • 您实际上可以从函数调用存储过程,从 SQL Server 2005 到 SQL Server 2008 R2,但是以一种非常hacky 且不推荐但有效的方式 XD。只要存储过程返回单个结果集。

标签: sql-server sql-server-2000


【解决方案1】:

您不能在函数内执行存储过程,因为假设这样的过程可能会引起副作用,例如表更改。

可以考虑将您的函数重铸为存储过程,从而允许内部存储过程调用,但请注意,这样做充满了危险、警告和危险,正如详细讨论的 @987654321 @

【讨论】:

  • David..这是失败的..select ..,..,..,exec sp_GetCatalogNumber a.ProductId as CatalogNumber,.. from..
  • 您不能以这种方式调用 SP(作为 SELECT 中的字段)。可以做的就是给SP加一个OUTPUT参数,在调用SP中声明一个对应的变量,调用SP把结果放到输出参数中。然后,您可以将该变量包含在您的 SELECT 中。
猜你喜欢
  • 2013-04-19
  • 2015-03-13
  • 2021-08-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多