Thursday, April 21, 2016

dbmail: sending html table in the email




Declare
@xml nvarchar(max),
@body nvarchar(max)

 
 

SET @xml = CAST(( SELECT clientcode AS 'td','',right(FilenameStr,charindex('\',reverse(FilenameStr),5)-1) as 'td','', cast(importstartDate as varchar) as 'td','',cast(ImportEndDate as varchar) as 'td'

,'', totnum as 'td', '', totdups as 'td','', totloaded as 'td','', totfail as 'td', '', totskip as 'td' FROM #fileList order by HospitalCode, importstartDate FOR XML PATH('tr'),ELEMENTS) as nvarchar(MAX))

--select @xml



 

SET @body ='<html><body><H3> files list for date ' + @sqllasjobrundate + '-' + convert(varchar(8),getdate(),112) + ' </H3>




<table border = 1>

<tr>

<td> Hospital code</td> <td> Fine name </td> <td> Import start date </td></td> <td> Import end date </td>

<td> Total count in file </td><td> Total duplicates </td><td> Total imported </td><td> Total failed validation </td><td> Total skipped </td>


</tr>'





SET @body = @body + @xml +'</table></body></html>'

EXEC msdb.dbo.sp_send_dbmail

@profile_name = 'SQLMail@mycompany.com', -- replace with your SQL Database Mail Profile

@body = @body,

@body_format ='HTML',

@recipients = 'mail1@mycompany.com', -- replace with your email address

@subject = 'file log Report ' ;

end

No comments:

Post a Comment