• Thanks for the feedback. Here are a couple of ways of expanding on the number of rows you have to generate:

    WITH iTally (n) AS (

    SELECT TOP(SELECT TOP(1) [Rows] = COUNT(*) FROM #table2 GROUP BY id1 ORDER BY COUNT(*) DESC) n

    FROM (VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10)) units (n)

    ) -- max 10 rows

    SELECT id, value, id1, value1

    FROM #Table1 t1

    CROSS JOIN iTally x

    LEFT JOIN (SELECT id1, value1, rn = ROW_NUMBER() OVER(PARTITION BY id1 ORDER BY value1) FROM #Table2) t2 ON t2.id1 = t1.id AND t2.rn = x.n

    ;

    WITH

    E1 (n) AS (SELECT 1 FROM (VALUES (0),(0),(0),(0),(0),(0),(0),(0),(0),(0)) E1 (n)), --10E+1 or 10 rows

    E2 (n) AS (SELECT 1 FROM E1 a, E1 b), --10E+2 or 100 rows

    iTally (n) AS (SELECT TOP(SELECT TOP(1) [Rows] = COUNT(*) FROM #table2 GROUP BY id1 ORDER BY COUNT(*) DESC)

    n = ROW_NUMBER() OVER(ORDER BY (SELECT NULL))

    FROM E2 a, E2 b) --10E+4 or 10,000 rows max

    SELECT id, value, id1, value1

    FROM #Table1 t1

    CROSS JOIN iTally x

    LEFT JOIN (SELECT id1, value1, rn = ROW_NUMBER() OVER(PARTITION BY id1 ORDER BY value1) FROM #Table2) t2 ON t2.id1 = t1.id AND t2.rn = x.n

    ;

    “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