title: How to pass output parameter to a Stored Procedure?
body: <p>I have written a stored procedure with the following format:</p>
  
  <pre><code>ALTER PROCEDURE usp_data_migration 
     (@sourceDatabase varchar(50),
      @sourceTable varchar(50),
      @targetDatabase varchar(50),
      @targetTable varchar(50),
      @finaloutput varchar(max) output)
  AS
  BEGIN
  ----Set of SQL Blocks
  
  
  END
  </code></pre>
  
  <p>Then, I am executing the procedure:</p>
  
  <pre><code>DECLARE @finaloutput1 varchar(300)
  
  EXEC usp_data_migration 'Yousuf', 'emp', '[City Branch]', 'emp_tgt', @finaloutput1 output 
  
  SELECT @finaloutput1 
  </code></pre>
  
  <p>By executing this way I don't proper output. </p>
  
  <p>When I execute this way:</p>
  
  <pre><code>DECLARE @finaloutput1 varchar(300)
  
  EXEC usp_data_migration @sourceDatabase = 'Yousuf',
                          @sourceTable = 'emp',
                          @targetDatabase = '[City Branch]',
                          @targetTable = 'emp_tgt',
                          @finaloutput1 output 
  
  SELECT @finaloutput1 
  </code></pre>
  
  <p>I get an error message saying:</p>
  
  <blockquote>
    <p>Msg 119, Level 15, State 1, Line 41<br>
    Must pass parameter number 5 and subsequent parameters as '@name = value'. After the form '@name = value' has been used, all subsequent parameters must be passed in the form '@name = value'.</p>
  </blockquote>
  
  <p>And if I removed my output parameter and execute the procedure, I get my desired output but I am not able to get my result as an output.</p>
  
  <pre><code>EXEC usp_data_migration @sourceDatabase = 'Yousuf',
                          @sourceTable = 'emp',
                          @targetDatabase = '[City Branch]',
                          @targetTable = 'emp_tgt'
  </code></pre>
  
  <p>What should I do?</p>
  
  <p>Thanks in advance.</p>