There might be number of questions regarding calling stored procedure from another stored procedure in SQL Server, or passing output value from stored procedure to another. But, I have a problem calling a stored procedure having output value, it always return error converting varchar
to int
.
Stored procedure #1:
CREATE PROCEDURE [dbo].[SP1]
@VarIn VARCHAR(MAX),
@VarOut VARCHAR(MAX) OUTPUT
AS
BEGIN
SET @VarOut = '20, 21'
END
Stored procedure #2
CREATE PROCEDURE [dbo].[SP2]
@Var1 VARCHAR(MAX)
AS
BEGIN
DECLARE @InstNo VARCHAR(MAX)
EXEC [dbo].[SP1] NULL, @InstNo OUTPUT
SELECT @InstNo
END
I'm using right click on the stored procedure to execute it:
DECLARE @return_value int
EXEC @return_value = [dbo].[SP2]
@Var1 = NULL
SELECT 'Return Value' = @return_value
GO
The error message is
Conversion failed when converting the varchar value '20, 21' to data type int
By the way, I got reference from the accepted answer from this question.