|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: 2 days ago @ 2:21 PM
Points: 79,
Visits: 353
|
|
Hi
I want to send query results by email using xp_sendmail procedure. I am able to send but the data formatted in wrong way.
How to send query result with proper format?
or
how to attach a FORMATTED query result file in the email?
Any help?
Thanks, BMR
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Today @ 2:19 AM
Points: 217,
Visits: 697
|
|
| You can use reporting service Subscriptions
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: 2 days ago @ 3:21 AM
Points: 563,
Visits: 943
|
|
Heres an example of a SELECT statement I use and it comes out nicely formatted :
DECLARE @tableHTML VARCHAR(MAX) DECLARE @tEmailList VARCHAR(MAX) DECLARE @tProfile VARCHAR(128) DECLARE @tEmailSubject VARCHAR(2048)
SELECT @tEmailList = email_address ,@tEmailSubject = CAST(@@SERVERNAME AS VARCHAR(128)) + ' - DB_Admin.dbo.usp_sel_InfoOS' ,@tableHTML = N'<H2>Database Report for Server: ' + @@SERVERNAME + '</H2>' + N'<table border="1">' + N'<tr> <th>Host Name</th> <th>OS Name</th>' + CAST ( ( SELECT td = [HostName] ,'' ,td = [OSName] ,'' FROM [DB_Admin].[dbo].[tbl_InfoOS] FOR XML PATH('tr'), TYPE) AS NVARCHAR(MAX)) + N'</table> This was generated by the <i>DB_Admin.dbo.usp_sel_InfoOS</i> Stored Procedure ' FROM msdb.dbo.sysoperators WHERE [name] = 'DBA'
EXEC msdb.dbo.sp_send_dbmail @profile_name = @tProfile ,@recipients = @tEmailList ,@subject = @tEmailSubject ,@body_format = 'html' ,@body = @tableHTML
|
|
|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: 2 days ago @ 2:21 PM
Points: 79,
Visits: 353
|
|
|
|
|