title: Pass parameters to sql agent job Transact-SQL Script (T-SQL)
body: <p>We have 10 databases (1 per location) and 1 master database on the warehouse server. These 10 databases correlate to their OLTP counterpart on another server.  I created a stored procedure in the master database to move data from the source to the destination. </p>
  
  <p>Instead of creating a cursor and looping though all of the databases, I was trying to see if there is a way to pass a parameter into a SQL Server Agent Job for each database – Essentially having 10 SQL Agent Jobs (1 per database)</p>
  
  <p>Is there a way in the Job > Steps > Command Window to declare a variable for the school and have it pass into the replicate stored procedure? </p>
  
  <p>Job 1</p>
  
  <pre><code>Declare @Source_DB varchar(max)
          @Target_DB Varchar(max)
  
  Set @Source_DB = ‘School_1’
  Set @Target_DB= ‘DW_School_1’
  
  Exec Replicate @Source_DB, @Target_DB
  </code></pre>
  
  <p>Job 2</p>
  
  <pre><code>Declare @Source_DB varchar(max)
          @Target_DB Varchar(max)
  
  Set @Source_DB = ‘School_2’
  Set @Target_DB= ‘DW_School_2’
  
  Exec Replicate @Source_DB, @Target_DB
  </code></pre>
  
  <p>Job 3</p>
  
  <pre><code>Declare @Source_DB varchar(max)
          @Target_DB Varchar(max)
  
  Set @Source_DB = ‘School_3’
  Set @Target_DB= ‘DW_School_3’
  
  Exec Replicate @Source_DB, @Target_DB
  </code></pre>
  
  <p>Job 4…....</p>