Sql – Executing a stored procedure within a stored procedure

sqlsql serversql-server-2005stored-procedurestsql

I would like to execute a stored procedure within a stored procedure, e.g.

EXEC SP1

BEGIN

EXEC SP2
END

But I only want SP1 to finish after SP2 has finished running so I need to find a way for SP1 to wait for SP2 to finish before SP1 ends.

SP2 is being executed as part of SP1 so I have something like:

CREATE PROCEDURE SP1
AS
BEGIN

EXECUTE SP2

END

Best Answer

T-SQL is not asynchronous, so you really have no choice but to wait until SP2 ends. Luckily, that's what you want.

CREATE PROCEDURE SP1 AS
   EXEC SP2
   PRINT 'Done'