ExecSQL outputs multiple updates script to variable

  • EamonSQL


    Points: 2298


    I have an ExecSQL task that generates many UPDATE statements which I would like to store as a variable and used in a subsequent ExecSQL statement.

    Is this possible? So far I have tried to store the output as a variable but then it fails.

    Any help welcome on this.






  • Thom A

    SSC Guru

    Points: 98617

    Do you mean you're generating Dynamic SQL? Where is this variable you are wanting to "store" the dynamic SQL in, SSIS or SQL Server (if the latter, then surely you already have a variable as you're executing dynamic SQL with sp_executesql). If you do want to store the value in SSIS, do these statements return any other datasets?


    Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.

  • Phil Parkin

    SSC Guru

    Points: 244441

    If you are running some SQL which returns a result set of T-SQL queries, the answer is yes.

    Return the result set to an Object variable, which should be shredded within a Foreach container, which itself would contain an ExecuteSQL task whose command would be set from an Expression, to contain the text from the shredded result set.

    • This reply was modified 11 months, 3 weeks ago by  Phil Parkin. Reason: Fix typos

    If the answer to your question can be found with a brief Google search, please perform the search yourself, rather than expecting one of the SSC members to do it for you.
    See https://www.sqlservercentral.com/articles/forum-etiquette-how-to-post-datacode-on-a-forum-to-get-the-best-help/ for details of how to post T-SQL code-related questions.

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

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