Alex Jeffery
Alex Jeffery

Reputation: 187

Can you pass the result of a function as parameter to stored procedure?

Using SqlServer 2005, is it possible to do something like this where SomeFunction returns a value. Eg 1234

EXEC [dbo].[SomeStoredProcedure] @SomeParameter = SomeFunction()

Upvotes: 1

Views: 1260

Answers (2)

Tuan-Tu Tran
Tuan-Tu Tran

Reputation: 31

Seems I don't have enough reputation to comment on the accepted answer.

Here's a more concise syntax where the declaration and the assignation of the variable is done in one line:

Declare @FunctionResult int = dbo.YourFunction()

Exec dbo.YourStoredProcedure @FunctionResult

Upvotes: 0

codingbadger
codingbadger

Reputation: 44024

You will need to declare a variable first to hold the result of the function. You can then pass the variable to the stored procedure

Declare @FunctionResult int

Select @FunctionResult = dbo.YourFunction()

Exec dbo.YourStoredProcedure @FunctionResult

Upvotes: 5

Related Questions