 ORDER BY sd.name ,
         bp.DBName
        ;
-       ';
---SELECT  @SQL;
-EXEC (@SQL);
+';
+
+IF @debug = 1 PRINT(@SQL);
+ELSE
+EXEC(@SQL);
+

/*
Author: Buck Woody
Original link: https://thelonedba.wordpress.com/2016/07/18/which-databases-were-backed-up-in-which-backup-task/
*/


DECLARE @SQL VARCHAR(MAX);
DECLARE @RunStartedList VARCHAR(MAX);
DECLARE @NumDays INT;
SELECT  @NumDays = 10; -- not doing this as a single line declare-define, as we might be running on older versions.
 
IF @NumDays > 0
    BEGIN

                                FOR
                                  XML PATH('')
                                ), 1, 2, '');

IF @RunStartedList IS NULL THROW 50000, @THROW50000, 1;

SELECT  @SQL = '
WITH    JobRuns
          AS ( SELECT   jh.instance_id ,
