• serg-52 (2/20/2014)


    Then JOIN them

    select x.R1,x.R2,x.R3, y.C1,y.C2,y.C3

    from Database.table1 as x

    join Database.table2 as y

    to get all possible combinations aka cartesian product.

    Restrict combinations using WHERE clause

    http://technet.microsoft.com/en-us/library/ms191517(v=sql.105).aspx

    On its own, join will raise an error.

    select x.R1,x.R2,x.R3, y.C1,y.C2,y.C3

    from Database.table1 as x

    CROSS JOIN Database.table2 as y

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden