Capture script/statement output?

  • Hi, folks!

    Is there any way to capture the text output of a multiline dynamic TSQL query into a TSQL variable?

    NB: "the text output" means all I can see in the messages tab of a query window in SSMS, e.g. the warnings, row counts, results of PRINT statements and so on.

    Seems to me I'm looking for a functionality similar to the @query parameter of "sp_send_dbmail", but within a TSQL script/ procedure.

    Any ideas?

    Regards from Berlin/Germany

    SeBaFlu

  • You could try capturing the statements using trace events. You just need to be careful because that will capture lots of information. Either turn it on then turn it off immediately or provide enough filtering to avoid capturing too much information, probably both.

    ----------------------------------------------------The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood... Theodore RooseveltThe Scary DBAAuthor of: SQL Server 2017 Query Performance Tuning, 5th Edition and SQL Server Execution Plans, 3rd EditionProduct Evangelist for Red Gate Software

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

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