Creating a new table from two existing tables with every combination possibility

sql, sql-server, sql-server-2012

Solution

I think you can just do

SELECT * INTO #c FROM #a,#b

Problem

I have two temporary tables #a and #b both filled with integer values. Let's say they both contain 10 rows with values 1-10. I want to create a third temporary table #c that contains every possible combination of a and b. So it would have 100 rows total with (1,1), (1,2) ... (10, 10). How would I go about doing this in SQL. The implementation I'm using is SQL Server 2012.

Original source