• Hey, my pleasure, happy to help out.

    I tweaked this solution just a little further, noticing on my server that DB Mail tends to get caught as a long running process. You could also add 'suspended' to the status exception list if you are sure your processes don't go to sleep. Some logic can be added at the end to check for a count of lines where sqltext is not null, then proceed to mail out the details:

    SELECT @cnt = count(*)

    FROM @LongRunningQueries

    WHERE sqltext IS NOT NULL and sqltext <> ''

    IF @cnt > 1

    BEGIN

    -- set subject to include server name

    SET @mySubject = @@SERVERNAME + ': Long Running Query Found'

    -- if @tableHTML is NULL, mail will not get sent

    EXEC msdb.dbo.sp_send_dbmail

    --@profile_name = 'DEFAULT',

    @recipients= 'you@yourdomain.com',

    @subject = @mySubject,

    @body = @tableHTML,

    @body_format = 'HTML';

    END