title: Loop in stored procedure in SQL server
body: <p>I need help with writing stored procedure that calls another stored procedure and passes values to it. So far this was done in C#, now I want to move it to stored procedure and make an SQL agent job that calls it at specific time. Any ideas? This is the case.   </p>
  
  <p><code>Table A</code>:</p>
  
  <pre><code>PK_TableA_ID
  </code></pre>
  
  <p><code>Table B</code>:</p>
  
  <pre><code>PK_TableB_ID
  </code></pre>
  
  <p>Stored procedure <code>SP1</code>:</p>
  
  <pre><code>@TableA_ID
  @TableB_ID
  </code></pre>
  
  <p>I need this but in T-SQL</p>
  
  <pre><code>foreach(var TableAId in TableA)
  {
  foreach(var TableBId in TableB)
  {
  //call stored procedure 
  SP1(TableAId, TableBId);
  }
  }
  </code></pre>