Given a simple stored procedure, that populates a OUTPUT
parameter and also RETURN
s a value, such as:
CREATE PROCEDURE sp_test
(
@param_out INT OUTPUT
)
AS BEGIN
SELECT @param_out = 9
RETURN 2
END
How can I call this procedure using sp_executesql
and capture both of these values?
I've tried:
DECLARE @ret INT, @param_out INT
EXEC SP_EXECUTESQL N'EXEC @ret = sp_test',
N'@ret INT OUTPUT, @param_out INT OUTPUT',
@ret OUTPUT,
@param_out OUTPUT
SELECT @ret, @param_out
However this complains that @param_out
was not supplied:
Procedure or function 'sp_test' expects parameter '@param_out', which was not supplied.