title: Executing Stored Procedure via sp_executesql
body: <p>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 ...</p>
  
  <pre><code>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
  </code></pre>
  
  <p>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?</p>