How a batch can get how much CPU it used in SQL Server 2019
Is there a statement I can put at the end of a batch to find out how many milliseconds of CPU it used? Something like SET STATISTICS TIME but for the whole batch, not each statement.
I'm not aware of something that aggregates the statistics of each batch. The actual execution plan might total it for you somewhere in the plan XML or properties?
If you execute a single batch at a time, you can use Richie Rump's simple yet awesome http://statisticsparser.com/ tool to aggregate the individual statistics of each statement into totals.
It even formats it all into nice readable tables, both for the individual statistics and the totals at the end. It will parse both
If you use https://www.sentryone.com/plan-explorer and open the actual execution plan of your batch in it, it also gives you the aggregated
TIMEstatistics on the toolbar.