Can DatabaseMail attach a formatted Excel file?

  • Hello,

    I have followed the advise on the post for the following and have place a 'tab' in the query_result_seperator and the csv file is still opening incorrectly.

    I would just like to verify that I place a ' then hit the TAB key and close with '

    Any help would be appreciate.

    Code:

    exec msdb.dbo.sp_send_dbmail @recipients = '@.org;@.net;',

    @body = 'Here are the visits :',

    @query = 'exec usp_nh_PharamacyInterventionExport',

    @query_attachment_filename = 'results.csv',

    @query_result_separator = '',

    @subject = 'Payors Changed Yesterday',

    @query_result_header = 1,

    @attach_query_result_as_file = 1,

    @execute_query_database = 'it'

    thank you

  • Try using CHAR(9) instead of using a TAB from the Keyboard, like Doug suggested a few posts earlier.

  • Tahnk you Jack that worked.

  • just stumbled across this thread. worked a treat thanks.

  • I had a similar problem exporting a CSV file from SSRS, where Excel would open the file as a single column. Turned out that the default SSRS export encoding for CSV was unicode, and Excel did not know how to handle that. I found the "Render" section in rsreportserver.config where you can override the encoding - set it to ASCII and that fixed my problem.

    Not exactly the same as the OP's issue but hopefully this will help somebody.

  • Thanks, Ted!

  • Hi, would it be possible to post the full script you got working please. Thank you.

  • I'd like to see the script too. Trying to get a tab delimiter to work. the char(9) doesn't work

  • Thanks a lot. it worked for me also.

    But still i am getting ------ one complete row after the header columns

  • Lavanyasri (11/30/2015)


    Thanks a lot. it worked for me also.

    But still i am getting ------ one complete row after the header columns

    I started this thread years ago - brings back memories hehe :w00t:

    Funny, I just updated a query to fix this very issue you mentioned.

    Step 1: Prepare a table with your data AND a single row that will become your column headings (using UNION ALL), as follows:

    create table temptbl(ACCOUNT VARCHAR(15),FACILITY VARCHAR(255),SORTORDER INT)

    insert into temptbl(account,facility,sortorder)

    SELECT 'ACCOUNT','FACILITY',0 -- these will be your column headings

    UNION ALL

    SELECT

    ACCOUNT,

    FACILITY,

    1 -- these are your rows of data with a sort order of 1 to make sure they are situated below your column headings

    FROM someothertbl

    Then in your database mail code, remove the automatic headings, because those come with the annoying dashes row that you're wanting to get rid of and populate your file making sure its sorted by SORTORDER:

    @profile_name = 'YOURPROFILE',

    @recipients = 'YOUR EMAIL ADDRESSES',

    @subject = 'SUBJECT',

    @query = 'set nocount on;SELECT account,facility FROM TEMPTBL order by sortorder',

    @attach_query_result_as_file = 1,

    @query_result_separator = '' ,

    @query_result_no_padding = 1,

    @query_result_header =0,

    @query_attachment_filename = 'BOOK1.csv'

    Hope this helps.

Viewing 10 posts - 16 through 24 (of 24 total)

You must be logged in to reply to this topic. Login to reply