2012-09-21 82 views
0

可能重复一个用户定义的标量函数:
Cast integer and concatenate to varchar in TSQL呼叫内的执行语句

我已经创建了两个标量函数,每个返回uniqueidentifer类型。我需要在执行语句中调用这些过程,但我似乎有语法错误。

Exec spModifyProductPropertyValue 
    @PAVID, 
    fnGetPropertyIDbyLabel(@Label7, @USPID, 0, 1), 
    @ProductID, 
    @Value7, 
    fnGetPINID(@7PIN), 
    0, 
    @counter out 

我注意到那是什么,当我单独调用的函数,然后通过使用来自theprevious调用的输出上面的号召,像这样

Declare 
     @PropertyID as uniqueidentifier = null 

Select @PropertyID = fnGetPropertyIDbyLabel(@Label7, @USPID, 0, 1) 

Exec spModifyProductPropertyValue 
     @PAVID, 
     @PropertyID, 
     @ProductID, 
     @Value7, 
     fnGetPINID(@7PIN), 
     0, 
     @counter out 

编译器不会抱怨太多。这种方法的问题是我最终创建了很多这些临时变量(差不多50),这是我想尽量避免的。我希望得到这个正确的任何帮助,请。

+0

阅读此:http://stackoverflow.com/questions/5967035/using-function-as-a-parameter-when-executing-a-stored-procedure。这是不可能的。 – prashanth

回答

-1

你需要有主人的前缀:

Exec spModifyProductPropertyValue 
    @PAVID, 
    dbo.fnGetPropertyIDbyLabel(@Label7, @USPID, 0, 1) as GetPropertyID, 
    @ProductID, 
    @Value7, 
    dbo.fnGetPINID(@7PIN) as GetPINID, 
    0, 
    @counter out 

Awnser在这里:SQL User Defined Function Within Select

+0

这样会导致不正确的语法错误。 – Kobojunkie

0

的语法UDF

expression... function_name(value_1, value_2, ... value_n)... 

所以,你只能传递值,而不是表达式。

由于使用函数是一个表达式, 另一功能

 Exec spModifyProductPropertyValue 
    @PAVID, 
    dbo.fnGetPropertyIDbyLabel(@Label7, @USPID, 0, 1) as GetPropertyID, --Expression 
    (..) 

的呼叫内是不可能的。

所以,是的,你将不得不创建变量。但如果所有的都是int,也许你可以创建一个并在每次使用函数时使用它。 或者修改你的函数只做两件功能所做的事情。