SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

HTML Table Results For Email

By M Higgins,

This stored procedure will take a pre-defined view, table or temp table and return the results as an HTML table formatted string.  This can then be used with email to send better formatted emails.

Example usage

DECLARE @GeneratedHTML NVARCHAR(MAX);
EXEC sp_GenerateHTMLTableResults @ResultsTableName = N'<TableName>' ,-- Can be a tablename, temp table or view
                                  @GeneratedHTML = @GeneratedHTML OUTPUT 
EXEC msdb.dbo.sp_send_dbmail @profile_name = NULL ,
                             @recipients = 'someone@domain.com' ,
                             @blind_copy_recipients = '' ,
                             @subject = 'HTML Table Results' ,
                             @body = @GeneratedHTML ,
                             @body_format = 'HTML'

Total article views: 356 | Views in the last 30 days: 356
 
Related Articles
FORUM

Formatting, Formatting, Formatting!

Percentage Formatting

FORUM

Format File

Format File

FORUM

smalldatetime format

smalldatetime format

FORUM

Format column

Format column

FORUM

Date Formatting

Date Formatting

Tags
formatting    
html    
mail    
 
Contribute