I am attempting to execute a Stored Procedure within another stored procedure. The catch is that the stored procedure name is dynamically built within the first procedure. Here is an example of what I am trying to do …
CREATE PROCEDURE SPINSVALUE_12345 @guid uniqueidentifier AS DECLARE @returnValue bit DECLARE @spToExec NVARCHAR(255) SET @returnValue = 0 WHILE (@returnValue=0) BEGIN SET @spToExec = 'SPINSVALUE_' + REPLACE(@guid, '-', '_') ... DO OTHER STUFF ... EXEC sp_executeSQL @spToExec, N'@returnValue BIT OUTPUT', @returnValue OUTPUT END END
I can’t seem to get the sp_executeSQL to work. Is it possible to execute a stored procedure this way and get a value from the OUTPUT parameter?
does the proc have a return value or an output value? here is an example
BTW I think that this is a bad idea to have many procs that do similar thing, maybe you need to refactor