email excel file using sp_send_dbmail

  • I have a sql job that uses a query to fetch results and then email the results in a text file.

    Now I have to email the same results as an excel.

    Can someone advice me how can I do that?

    Thanks

  • Just change the file extension to .xls and tab as value for @query_result_separator



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • Be very careful sending excel files through the mail. They tend to be too large for most people to send or receive.

    You can either zip the file and send the zip via dbmail or you can FTP the Excel file.

    Also, be leery of sending an unencrypted file via dbmail, especially if you're sending it "out of house." Privacy laws can be a royal *itch and can get you fired if someone who's not supposed to get that data ends up intercepting or receiving it.

    Lastly, from experience, changing the extension does not always work -- when changing just an existing file extension. (EDIT: Though Lutz's suggestion is a good one). You may have to use an SSIS package to load an excel file destination, instead of your text file, if this is a frequent event. If it's a one-off thing, consider importing the text file into excel and save it to the destination you intend to get it with dbmail.

    Does that help?

    Brandie Tarvin, MCITP Database AdministratorLiveJournal Blog: http://brandietarvin.livejournal.com/[/url]On LinkedIn!, Google+, and Twitter.Freelance Writer: ShadowrunLatchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.

Viewing 3 posts - 1 through 2 (of 2 total)

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