Passing a function as an argument to a stored procedure

Is there a way to send functions as parameters of stored procedures?

create procedure stp_dummy @input nvarchar(255) as select @input exec stp_dummy a_function_that_returns_string('abracadabra') 

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

+4
source share
2 answers

I know that this is not the answer you are looking for, but the only way to do this is to declare a local variable, assign it a function value and use it as a 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 
+4
source

No, this is a limitation of SQL Server. You will need to do something like what Kurt demonstrated.

0
source

Source: https://habr.com/ru/post/1384924/


All Articles