Link to home
Start Free TrialLog in
Avatar of VitaminD
VitaminDFlag for United States of America

asked on

Database Mail Formatting Question

Declare @report_file_name varchar(30),
@sql varchar(max),
@emailbody varchar(4000)


      set @sql = N' SET NOCOUNT ON
      EXEC  AdventureWorks.HumanResources.EmployeeGender ''M'''
      PRINT @sql
      SET @report_file_name =  'HumanResources.EmployeeGender' +     convert(varchar(10),getdate(), 112) + '.txt'

SET @emailbody = 'The result from EmployeeHireProcedure as today(yyyy.mm.dd):  '+ convert(varchar(10),getdate(), 102)

      Exec msdb.dbo.sp_send_dbmail
                        @profile_name = 'AdminAccount',
                        @recipients = 'xxxx@gmail.com',
                        @subject = 'T-SQL Query Result',
                        @body = @emailbody,
                        @body_format = 'TEXT',
                        @query = @sql,
                        @attach_query_result_as_file = 1,
                        @execute_query_database = 'AdventureWorks',                        
                        @query_attachment_filename = @report_file_name,
                        @query_result_header = 1,
                        @query_result_no_padding = 1,
                        @query_result_separator = '',
                        @query_result_width = 1000;


The Email file I receive is not formatted properly
How can I return this info in a readable format
Possibly a csv file or something like that
This is just a test
Tomorrow I need to output the result of a stored procedure from one of our production databases

Any help would be appreciated
Thanks in advance
ASKER CERTIFIED SOLUTION
Avatar of lcohan
lcohan
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial