Is is possible to Dynamic join on EXECUTE table column

  • There is always the option of dumping the results of the execution into a temp table and joining to that.

    Here's a rather trivial example but it will hopefully illustrate the idea...

    DECLARE @sql VARCHAR(255) = '

    SELECT

    x.SomeNumber

    FROM (VALUES (1),(2),(3),(4),(5)) x (SomeNumber)'

    IF OBJECT_ID('tempdb..#temp') IS NOT NULL

    DROP TABLE #temp;

    CREATE TABLE #temp (

    SomeNumber TINYINT

    );

    INSERT #temp (SomeNumber)

    EXEC (@sql);

    SELECT

    t1.SomeNumber AS t1_Num,

    t2.SomeNumber AS t2_Num

    FROM

    #temp t1

    CROSS JOIN #temp t2

Viewing post 16 (of 15 total)

You must be logged in to reply to this topic. Login to reply