Corovei Andrei
Corovei Andrei

Reputation: 1668

Passing a function as argument to a stored procedure

Is there any way to send functions as parameters to stored procedures?

create procedure stp_dummy 
@input nvarchar(255)
as select @input

exec stp_dummy a_function_that_returns_string('abracadabra')

(Of course that I know that the function can be called previously but I would like to know if the direct solution is available.)

Upvotes: 4

Views: 130

Answers (2)

Curtis
Curtis

Reputation: 103428

I know this isn't the answer you're looking for, but the only way to do this is to declare a local variable, assign the function value to this, and use this as your parameter value:

DECLARE @input nvarchar(255)
SET @input = a_function_that_returns_string('abracadabra')
EXEC stp_dummy @input=@input

With SQL Server 2008, this can be done in 2 lines:

DECLARE @input nvarchar(255) = a_function_that_returns_string('abracadabra')
EXEC stp_dummy @input=@input

Upvotes: 4

Chris Townsend
Chris Townsend

Reputation: 3162

No, this is a limitation of SQL Server. You'll have to do something like what Curt demonstrated.

Upvotes: 0

Related Questions