2013-03-02 41 views
0

调用远程函数后,标量值函数失败。有没有办法调用远程服务器功能?函数内不允许远程函数调用

这是你无法执行存储函数内的程序代码

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 
+0

讨论我会做相反的事情。将逻辑放入函数中并从存储过程中调用函数。 – darin 2013-03-02 04:52:21

+0

实际上,您可以从函数(从SQL Server 2005到SQL Server 2008 R2)调用存储过程,但以一种非常黑客且不推荐但有效的方式XD。只要存储过程返回单个结果集。 – 2013-12-26 23:27:56

回答

1

,因为假设的是,这样一个过程可能引起副作用,如变更表。

可以思忖重塑你的函数作为存储过程,从而使内部存储过程调用,但是要知道,这样做是充满危险,警告和危险。如果尽可能详尽here.

+0

David..This is failing..select ..,..,..,exec sp_GetCatalogNumber a.ProductId as CatalogNumber,.. from .. – user1532976 2013-03-04 19:02:52

+0

您不能以这种方式调用SP(作为SELECT中的字段) 。你可以做的是向SP添加一个OUTPUT参数,在调用SP中声明一个相应的变量,然后调用SP将结果放入输出参数中。然后,您可以在SELECT中包含该变量。 – 2013-03-04 20:12:56