Hi Johnathan,
I have been using a method that once I found on internet if now here at sqlservercentral and has helped me identifying certain elements and information on one or more DBs in my environment and notifying me via the DBMail separately ..
<code>
ALTER PROCEDURE [dbo].[USP_CollectDBInformation_Display]
@DBName nvarchar(32) = '_N/A'
AS
BEGIN
SET NOCOUNT ON;
select servername,
databasename,
sum(filesizemb) as FilesizeMB,
[Status],
RecoveryMode,
sum(FreeSpaceMB)as FreeSpaceMB,
sum(freespacemb)*100/sum(filesizemb) as FreeSpacePct,
InputDate,
year(InputDate) TheYear,
month(InputDate) TheMonth,
day(InputDate) TheDay,
datepart(qq, InputDate) TheQuarter
from dbinformation
where filesizemb > 0 and
databasename like
case @DBName
when '_N/A' then '%%'
else '%' + @DBName + '%'
end
group by servername,databasename, [Status], RecoveryMode, InputDate
END
</code>
and then the email of course
<code>
Exec msdb.dbo.sp_send_dbmail
@profile_name = 'LocalServer'
,@recipients = 'JohnE.sql@gmail.com'
,@query = ' your statement goes here '
,@Subject = 'DB Information'
,@Attach_query_result_as_file = 1;
</code>
Albeit, I like your method and definitely going to examine it in my test environment and I know that I am going to like it..
well done!
Cheers,
John Esraelo