DECLARE @tableHTML VARCHAR(max) SET @tableHTML = N'

- TITLE -

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