I using sql stored procedure for sending email with attachment.
I want to send email with excel attachment.
I used the following code
- DECLARE @Body VARCHAR(8000)
- DECLARE @Qry varchar(8000)
- SET @Body ='Hi PFA,'
- SET @Qry='set nocount on;select * from tblname'
- DECLARE
- @tab char(1) = CHAR(9)
- EXEC msdb.dbo.sp_send_dbmail
- @profile_name = 'Profilename' ,
- @recipients = 'receipentemail',
- @body= @Body,
- @query=@Qry,
- @subject='Send db mailer with attachment',
- @attach_query_result_as_file = 1,
- @query_attachment_filename='Report.xls'
but in excel is not proper it is disturbed columns and rows.
Please help me for proper excel attachment.