Hi,
Am getting the error message while trying to add mail part in the below query. Help me to getthe result as HTML mail
The below one is a part of the original query
select
d.Dbname,d.dbstatus,d.Recovery_Model,
(file_size_mb + log_file_size_mb) as DBsize,
d.file_Size_MB,d.Space_Used_MB,d.Free_Space_MB,
l.Log_File_Size_MB,log_Space_Used_MB,l.log_Free_Space_MB,fs.Freespace as DB_Freespace
from #dbsize d join #logsize l
on d.Dbname=l.Dbname join #dbfreesize fs
on d.Dbname=fs.name
order by Dbname
---------Here is my HTML body part which i tried--------------
DECLARE @table NVARCHAR(MAX) ;SET @table = N'<H1>DBSize</H1>' + N'<table border="1">' +
N'<tr><th>d.Dbname</th><th>d.dbstatus</th><th>d.Recovery_Model</th><th>DBSIZE</th><th>(file_size_mb + log_file_size_mb) as DBsize
</th><th>d.file_Size_MB</th></th><th>d.Space_Used_MB</th><th>d.Free_Space_MB</th><th>l.Log_File_Size_MB</th><th>log_Space_Used_MB</th>
<th>l.log_Free_Space_MB</th><th>fs.Freespace</th></tr>'
+ CAST ( ( SELECT [d.Dbname] AS 'td','',[d.dbstatus] AS 'td','',[d.Recovery_Model] AS 'td','', (file_size_mb + log_file_size_mb) AS 'td','',[FILE_SIZE_MB] AS 'td','',
[d.file_Size_MB] AS 'td','',[d.Space_Used_MB] AS 'td','',[d.Free_Space_MB] AS 'td','',[l.Log_File_Size_MB] AS 'td','',
[log_Space_Used_MB] AS 'td','',[l.log_Free_Space_MB] AS 'td','',[fs.Freespace] AS 'td'
from #dbsize d join #logsize l
on d.Dbname=l.Dbname join #dbfreesize fs
on d.Dbname=fs.name
order by Dbname
FOR XML PATH('tr'), TYPE ) AS NVARCHAR(MAX) ) + N'</table>' ;
EXEC msdb.dbo.sp_send_dbmail @profile_name='GmailAccount', --Change to your Profile Name
@recipients='mynamer@gmail.com', --Put the email address of those who want to receive the e-mail
@subject = 'DatabaseFileSizes', @body = @table, @body_format = 'HTML' ;
----Error message Part---
Invalid column name 'd.Dbname'.
Msg 207, Level 16, State 1, Line 107
Invalid column name 'd.dbstatus'.
Msg 207, Level 16, State 1, Line 107