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)
As
Begin
return --do your operation;
End
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
SQL Statements with Equals VS In
Efficient Way to Update All Rows in a Table
How to Change the Primary Key to Be Non-Clustered
Is There a Tool for Refactoring SQL, a Bit Like a Resharper for SQL
How to Find Values in All Caps in SQL Server
Checking Whether an Item Does Not Exist in Another Table
Modify Materialized View Query
Left Inner Join VS. Left Outer Join - Why Does the Outer Take Longer
How to Get the Max Row Number Per Group/Partition in SQL Server
Difference Between Information_Schema VS Sys Tables in SQL Server
Insert Record to SQL Table with Identity Column
What's the Best Practice of Naming Stored Procedure for T-Sql
Renaming a Column in Ms SQL Server 2005
Make H2 Treat Quoted Name and Unquoted Name as the Same
T-SQL Column Alias on Computed Column - Invalid Column Name
Differencebetween Prepared Statements and SQL or Pl/Pgsql Functions, in Terms of Their Purpose