Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


sp_send_dbmail attachement EXCEL file has error


sp_send_dbmail attachement EXCEL file has error

Author
Message
sunilk.net
sunilk.net
Forum Newbie
Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)

Group: General Forum Members
Points: 9 Visits: 142
Hi All,
Need you help on below.

I am generating the excel file and send email using "sp_send_dbmail". I even receive the email , but when i open the excel attachement has error shown as below.

ERROR:

The file you are trying to open,'~4595071.xls', is in a different format that specified by the file extension. Verify that the file is not corrupted and is from a truseted source before opening the file.


SOURCE CODE:

DECLARE @CURRDATE VARCHAR(10)
DECLARE @tab_char CHAR, @subject nvarchar(150), @query_attachment_filename nvarchar(150), @recipients nvarchar(300)

SET @CURRDATE = CONVERT(VARCHAR, GETDATE(),112)

SELECT @tab_char =' ',
@subject = 'Extraction file - ' + @currdate,
@query_attachment_filename = 'Extract_' + @currdate + '.xls',
@recipients = 'abcd@xxxx.com'



-- schedule extract to send alert

EXEC msdb.dbo.sp_send_dbmail
@recipients = @recipients,
@body = 'This document is to send extract',
@subject = @subject,
@profile_name = null,
@query ='SET NOCOUNT ON;
SELECT '''',''HEADER1'',''HEADER2'',''HEADER3'',''HEADER4'',''HEADER5'',''HEADER6'',''HEADER7'',''HEADER8''

UNION ALL
SELECT SELECT * from FROM ##EXTRACT',
@attach_query_result_as_file = 1,
@query_result_separator = @tab_char,
@query_result_width = 32767,
@exclude_query_output = 1,
@query_result_no_padding = 1,
@append_query_error = 1,
@query_result_header = 0,
@query_attachment_filename = @query_attachment_filename


Thanks,
Sunil.
Orlando Colamatteo
Orlando Colamatteo
SSCrazy Eights
SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)

Group: General Forum Members
Points: 8237 Visits: 14368
Just because you slap a .xls extension onto a file does not make it an Excel-format file. What you have is a CSV (Comma-Separated Value) file saved with a .xls extension. Yes, when someone double-clicks your email attachment it will open in Excel if they have it installed because that is the program Windows is configured to use to open files with a .xls extension when Excel is initially installed but the Excel program can tell that the file is not in Excel-format and that is the warning you are seeing. You would be better off saving the file with a .csv extension. If the email recipient has Excel installed then the file will still open in Excel because just like files with an .xls extension Windows is also configured to open .csv files in Excel when Excel is installed.

edit: spelling

__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search