title: How do I get every permutation in two totally unrelated tables with t-sql
body: <p>I have two tables that are indirectly related by another table</p>
  <blockquote>
  <p>TableA - ID, SomeFieldA</p>
  <p>TableB - ID, SomeFieldB</p>
  <p>TableAB - IDA, IDB, SomeFieldAB</p>
  </blockquote>
  <p>I have to generate data from the ground up.  So I've put some data in TableA, and I've put some data in TableB.  The problem is, I need to insert data into TableAB now, and I don't know how to generate a script that will do all the permutations of TableA and TableB together.</p>
  <p>For instance:</p>
  <p>Table A has two records:</p>
  <blockquote>
  <p>1, 'A'</p>
  <p>2, 'AA'</p>
  </blockquote>
  <p>Table B has two records:</p>
  <blockquote>
  <p>3, 'B'</p>
  <p>4, 'B'</p>
  </blockquote>
  <p>I want to insert the following data into TableAB:</p>
  <blockquote>
  <p>1, 3, 'first perm'</p>
  <p>1, 4, 'second perm'</p>
  <p>2, 3, 'third perm'</p>
  <p>2, 4, 'fourth perm'</p>
  </blockquote>
  <p>What's the easiest way to do this?</p>