0

Supposing I have two temporary tables

CREATE TABLE TableA
(
    SomeValue    NVARCHAR(64)
)

CREATE TABLE TableB
(
    SomeValue    NVARHCAR(64)
)

and a final table

CREATE TABLE TableC
(
    SomeValue1    NVARCHAR(64),
    SomeValue2    NVARHCAR(64)
),

what is the best way to insert into TableC every possible combination of values from TableA and TableB in a high-perfomance fashion? I know cursors must be the least thing to think about, but will two WHILE loops do it fast enough?

B.M
  • 533
  • 2
  • 8
  • 16

1 Answers1

3

A simple Cartesian product which is a CROSS JOIN (Wikipedia, MSDN)

INSERT TABLEC 
   (SomeValue1, SomeValue2)
SELECT
   TABLEA.SomeValue, TABLEB.SomeValue
FROM
   TABLEA CROSS JOIN TABLEB
gbn
  • 422,506
  • 82
  • 585
  • 676