• This is a great script, thanks for sharing it. I made a few little tweaks that others might find useful.

    ---I made @vRecipients a parameter that can be passed at the time of execution:

    CREATE PROCEDURE [dbo].[usp_SQL_Server_System_Report]

    @v_Output_Mode CHAR (1) = NULL

    ,@vUnused_Index_Days INT = 7

    ,@vRecipients AS NVARCHAR(128) = NULL

    AS

    .....

    ---and then commented out the declaration for it

    DECLARE @vOnline_Since AS NVARCHAR (19)

    -- DECLARE @vRecipients AS VARCHAR (MAX)

    DECLARE @vSQL_String AS NVARCHAR (MAX)

    .....

    ---also, I modified the part where the email is sent, so if there are multiple email profiles and/or no default mail profile, it will still work.

    IF @v_Output_Mode = 'E'

    BEGIN

    DECLARE @profname sysname

    SELECT@profname = name

    FROMmsdb.dbo.sysmail_profile

    WHEREprofile_id in (SELECT min(profile_id) FROM msdb.dbo.sysmail_profile)

    EXECUTE [msdb].[dbo].[sp_send_dbmail]

    @profile_name = @profname

    ,@recipients = @vRecipients

    ,@copy_recipients = @vCopy_Recipients

    ,@subject = @vSubject

    ,@body = @vBody

    ,@body_format = 'HTML'

    END

    The changes I made allow the report to be sent to anyone on the dba team.

    Hope these mods are helpful to others.