DECLARE @tableHTML VARCHAR(max)
SET @tableHTML =
N'
- TITLE -
' +
N'' + CONVERT(NVARCHAR, GETDATE(), 120) + N'' +
N'' +
N'
| Platform |
ID |
Name |
Ref |
Amount |
' +
CAST ( ( select
td = [platform], '',
td = id, '',
td = name, '',
td = Ref, '',
td = Amount
from ##temptable
FOR XML PATH('tr'), TYPE
) AS NVARCHAR(MAX) ) +
N'
' ;
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'DBA',
@recipients = 'dba@google.com',
@subject = 'Email title',
@body = @tableHTML,
@body_format = 'HTML';