title: Dynamically call a stored procedure from another stored procedure
body: <p>I want to be able to pass in the name of a stored procedure as a string into another stored procedure and have it called with dynamic parameters.  I'm getting an error though.</p>
  
  <p>Specifically I've tried:</p>
  
  <pre><code>create procedure test @var1 varchar(255), @var2 varchar(255) as
      select 1
  
  create procedure call_it @proc_name varchar(255)
      as
      declare @sp_str varchar(255)
      set @sp_str = @proc_name + ' ''a'',''b'''
      print @sp_str
      exec @sp_str
  
  exec call_it 'test'
  </code></pre>
  
  <p>So procedure call_it should call procedure test with arguments 'a', and 'b'.</p>
  
  <p>When I run the above code I get:</p>
  
  <blockquote>
    <p>Msg 2812, Level 16, State 62, Procedure call_it, Line 6
        Could not find stored procedure 'test 'a','b''.</p>
  </blockquote>
  
  <p>However, running test 'a','b' works fine.</p>