Union Exec's

  • Hello,

    how to change the code to make UNION between the results of the two exec's

    and the result to have two rows (one with 1 and the 2nd with 2)

    declare @s1 as varchar(100)

    declare @s2 as varchar(100)

    set @s1 = 'SELECT 1'

    set @s2 = 'SELECT 2'

    exec( @s1 )

    UNION

    exec( @s2 )

    Thanks,

    Regards

  • Create a temp table, use Insert ... EXEC to insert the output of the procedures into the table, then query the table.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • What about this...

    exec ( @s1+ ' UNION '+ @s2 )

  • Thanks a lot.

    About:

    What about this...

    exec ( @s1+ ' UNION '+ @s2 )

    that is nice, I have not thought about it. Unfortunately this query string is a sample, the real one is more complex.

    I created a stored procedure that inserts records and another one that merges them all.

    Have a great day,

    Iulian

Viewing 4 posts - 1 through 3 (of 3 total)

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