• Steve Jones - SSC Editor (2/1/2016)


    I don't think you can do this in a single statement. I might be wrong, but I suspect you could drop the results into a temp table, then query that with the servername pre-pended, i.e.

    select @@servername, *

    from #mytemp

    and then use this in some other code.

    I started to build the temp table required to do an INSERT...EXEC on the proc and capture the results. Anytime I do this work I find:

    1) it would be pretty time-consuming to read the code of the proc to determine the resultset

    2) a lot of the Agent procs already have an INSERT-EXEC in them and since you cannot nest INSERT...EXEC, a lot of times it's a dead-end

    So I bailed and recommended an SSIS solution. Adding a Derived Column to the SSIS Pipeline is trivial and the OP already knows which server they are talking to, and presumably has this in a Variable, since it sounds like they are iterating over a list of servers to capture this info.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato