Executing a Stored Procedure Within a Stored Procedure

Execute a stored procedure from within another stored procedure's SELECT statement?

The approach what you have tried is invalid. Instead of the X as the stored procedure convert it as user-defined function. like the below

Create function dbo.fnGetTypeDetail
@type varchar(50)
returns varchar(100)
return --do your operation;

And replace your query as:

SELECT name, type, dbo.fnGetTypeDetail(type) AS TypeDetail
FROM table

For sample, I created a scalar function. Based on your requirement you can create inline table valued function as per the example

Calling one stored procedure within another stored procedure using variables from first stored procedure

I'm executing procedures inside other procedures like this:

DECLARE @childResult int, @loaErrorCode int, @loaErrorMessage varchar(255) 
EXEC @childResult = [dbo].[proc_sub_getSomething] @schemes_id = @foo_schemes_i, @errorCode = @loaErrorCode OUTPUT , @errorMessage = @loaErrorMessage OUTPUT

Should it still not work you should edit your question to show your exact code.

Related Topics

Leave a reply