代码之家  ›  专栏  ›  技术社区  ›  Martin Boros

在255个字符处停止查询输出到CSV换行符

  •  6
  • Martin Boros  · 技术社区  · 7 年前

    我正在创建一个任务,以将SQL输出作为csv文件附加到SQL Server代理中发送电子邮件。通常没有问题,我的代码如下所示:

    declare @tab char(1) = char(9)
    EXEC  msdb.dbo.sp_send_dbmail
          @profile_name = 'MailProfile',
          @recipients = 'email@email.com', 
          @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
    

    这通常是可行的,但在当前查询中,列名是换行的,许多数据行是换行的,不存在换行符。看起来,只要行的长度超过255个字符,它就会这样做。有没有办法绕过这个?看起来可能和这个问题一样, SQL Email to CSV, Results have Line Splitting issues .

    1 回复  |  直到 7 年前
        1
  •  10
  •   Martin Boros    7 年前

    添加选项:

    @query_result_width=500
    

    修复了它