0

有没有办法将下面语句中的输出 CSV 格式化为 Excel 可以轻松读取?至于现在,它会将所有列乱成一列。我已经尝试过不同的破坏者。

EXEC msdb.dbo.sp_send_dbmail
    @profile_name = 'auto-reporting'
  , @recipients = @recipientsList   
  , @subject = 'MC Auto Reports'
  , @query = 'select * from test.dbo.temp'
  , @attach_query_result_as_file = 1
  , @query_result_separator =','
  , @query_result_no_padding = 1
  , @query_attachment_filename = @FileName;
4

2 回答 2

1

尝试在记事本中编辑生成的 .csv 文件。在第一行输入 [sep=,] 不带引号并保存。然后尝试在 Excel 中打开它,如果它正确显示,那么您需要在 Windows 中检查您的区域设置。

于 2015-04-08T07:34:04.313 回答
0

尝试改变

, @query_result_separator =','

, @query_result_separator = @separator

只需在发送电子邮件之前添加此代码

DECLARE @separator CHAR(1)
SET @separator = CHAR(9)

这使得 Excel 更喜欢的分隔符 TAB。

于 2015-04-09T00:59:51.703 回答