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.
Cross join will get all combinations
SELECT a.Col
, b.Col
FROM TableA a
CROSS JOIN TableB b
I think you can just do
SELECT * INTO #c FROM #a,#b
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With