@@ -343,7 +343,10 @@ DECLARE
343343 @log_database_schema nvarchar (1024 ),
344344 @max_event_time datetime2 (7 ),
345345 @dsql nvarchar (max ) = N ' ' ,
346- @mdsql nvarchar (max ) = N ' ' ;
346+ @mdsql nvarchar (max ) = N ' ' ,
347+ @actual_start_date datetime2 (7 ),
348+ @actual_end_date datetime2 (7 ),
349+ @actual_event_count bigint ;
347350
348351/* Use some sane defaults for input parameters*/
349352IF @debug = 1
@@ -2825,8 +2828,23 @@ BEGIN
28252828 ap .avg_worker_time_ms DESC
28262829 OPTION (RECOMPILE , LOOP JOIN , HASH JOIN );
28272830
2831+ /* Capture actual date range and event count from the data */
2832+ SELECT
2833+ @actual_start_date = MIN (event_time),
2834+ @actual_end_date = MAX (event_time),
2835+ @actual_event_count = COUNT_BIG (DISTINCT monitor_loop)
2836+ FROM #blocked
2837+ WHERE event_time IS NOT NULL ;
2838+
2839+ /* Use original dates if no data found */
2840+ SELECT
2841+ @actual_start_date = ISNULL (@actual_start_date, @start_date_original),
2842+ @actual_end_date = ISNULL (@actual_end_date, @end_date_original),
2843+ @actual_event_count = ISNULL (@actual_event_count, 0 );
2844+
28282845 IF @debug = 1
28292846 BEGIN
2847+ RAISERROR (' Actual date range: %s to %s, Event count: %I64d' , 0 , 1 , @actual_start_date, @actual_end_date, @actual_event_count) WITH NOWAIT ;
28302848 RAISERROR (' Inserting #block_findings, check_id -1' , 0 , 1 ) WITH NOWAIT ;
28312849 END ;
28322850
@@ -2845,7 +2863,13 @@ BEGIN
28452863 database_name = N ' erikdarling.com' ,
28462864 object_name = N ' sp_HumanEventsBlockViewer version ' + CONVERT (nvarchar (30 ), @version) + N ' .' ,
28472865 finding_group = N ' https://code.erikdarling.com' ,
2848- finding = N ' blocking for period ' + CONVERT (nvarchar (30 ), @start_date_original, 126 ) + N ' through ' + CONVERT (nvarchar (30 ), @end_date_original, 126 ) + N ' .' ,
2866+ finding = N ' blocking events from ' + CONVERT (nvarchar (30 ), @actual_start_date, 126 ) + N ' to ' + CONVERT (nvarchar (30 ), @actual_end_date, 126 ) +
2867+ N ' (' + CONVERT (nvarchar (30 ), @actual_event_count) + N ' total events' +
2868+ CASE
2869+ WHEN @max_blocking_events > 0 AND @actual_event_count >= @max_blocking_events
2870+ THEN N ' , limited to most recent ' + CONVERT (nvarchar (30 ), @max_blocking_events) + N ' )'
2871+ ELSE N ' )'
2872+ END + N ' .' ,
28492873 1 ;
28502874
28512875 IF @debug = 1
0 commit comments