Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop query output to CSV wrapping lines at 255 characters

I'm creating a task to send an email with a SQL output as a csv file attached in the SQL Server Agent. Normally not a problem, my code looks like this:

declare @tab char(1) = char(9)
EXEC  msdb.dbo.sp_send_dbmail
      @profile_name = 'MailProfile',
      @recipients = '[email protected]', 
      @subject = 'TheSubject',
      @body = 'TheBody',
      @query = 'select * from ##TempTableBeingUsed',      
      @Attach_Query_result_as_file = 1,
      @query_attachment_filename = 'report.csv',
      @query_result_separator = @tab,
      @query_result_no_padding=1,
      @exclude_query_output=0,
      @append_query_error =0,
      @query_result_header=1

And this normally works, but with the current query the column names are line wrapping, and a lot of the data rows are line wrapping, without a line break being present. It looks like it does this whenever the length of the row is more then 255 characters. Is there any way to bypass this? Looks it may be the same as this issue, SQL Email to CSV, Results have Line Splitting issues.

like image 591
Martin Boros Avatar asked Jan 05 '18 17:01

Martin Boros


1 Answers

Adding the option:

@query_result_width=500

fixed it

like image 200
Martin Boros Avatar answered Nov 13 '22 21:11

Martin Boros