如何从存储过程中调用函数
问题描述:
此质疑在我的采访中问到
This queastion asked in my interview
答
有几种方法,但其中一种是这样的:
Several ways, but one is like this:
DECALRE @variable Varchar(MAX)
SET @variable = dbo.YourFunction("some expression and/or value to pass to your function")
我给出了几个步骤:
1.创建一个将两个数字相加的函数
I am giving few steps:
1. Create a function for addition two number
CREATE FUNCTION AddTwoNumber
(
@first int,
@second int
)
RETURNS int
AS
Begin
declare @add int
SET @add= @first + @second
return @add
end
2.创建一个调用函数的存储过程
2. Create a stored procedure that call function
CREATE Procedure proc_AddTwoNumber
(
@first int,
@second int
)
AS
SELECT dbo.AddTwoNumber(@first,@second)
3.调用存储过程
3. call the stored procedure
exec proc_AddTwoNumber 12,13