SQL sp_send_dbmail with csv attachment

  • I have one table called stats where we collect the stats and top queries. I need to send report on regular basis for top queries.

    I'm trying to send email with sp_send_dbmail with CSV file attached. Issue is in result set i have 8 columns and one column is with SQL Statement so it has comma and carriage returns so when I open the csv file its not display data properly.

    Any idea how to fix this issue.

    Thanks

  • Hello.

    You can use the parameter @query_result_separator=';' this is a char(1) and change ',' separator to other as ';'

    https://msdn.microsoft.com/es-es/library/ms190307.aspx

    [ @query_result_separator= ] 'query_result_separator'

    Is the character used to separate columns in the query output. The separator is of type char(1). Defaults to ' ' (space).

    Regards.

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

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