Here's a simple stored procedure:
Now the following would show '123' in the result window:
But I want to set the output of this stored procedure to another variable:
This doesn't work! Anyone know what I am doing wrong?
Code:
CREATE PROCEDURE MyProc
AS
BEGIN
DECLARE @Query nvarchar(max)
SET @Query = 'SELECT 123'
EXEC(@Query)
END
Code:
EXEC MyProc
Code:
DECLARE @RetVal nvarchar(max)
EXEC @RetVal = EXEC MyProc
SELECT @RetVal