我使用sp_send_dbmail生成并发送文件,这些文件被馈送到其他程序。该程序采用"ANSI/ASCII“和"ISO-8859-1”编码。但我不能让sp_send_dbmail做一个。
过程调用如下所示
exec msdb.dbo.sp_send_dbmail
@profile_name= @profile_name,
@recipients = @recipients,
@body = @body,
@subject = @subject,
@attach_query_result_as_file = 1,
@query_result_header = 0,
@query_result_no_padding = 1,
@query = @query,
@query_attachment_filename = @fname,
@query_result_width = 4000,
@mailitem_id = @mailitem_id OUTPUT因此,附件是从传递的查询结果创建的。但由于某种原因,实际附加到邮件的结果文件是用UCS2 Little Endian编码的。有没有办法改变它?
发布于 2013-04-10 14:35:22
已找到允许在UTF/ANSI之间切换的解决方法。为此,您需要像这样修改sp_send_dbmail:
编写的IF(@AttachmentsExist = 1) BEGIN ....... END代码片段
` `IF (@AttachmentsExist = 1)
BEGIN
if (@ANSI_Attachment = 1)
begin
--Copy temp attachments to sysmail_attachments
INSERT INTO sysmail_attachments(mailitem_id, filename, filesize, attachment)
SELECT @mailitem_id, filename, filesize,
convert(varbinary(max),
substring( -- remove BOM mark from unicode
convert(varchar(max), CONVERT (nvarchar(max), attachment)),
2, DATALENGTH(attachment)/2
)
)
FROM sysmail_attachments_transfer
WHERE uid = @temp_table_uid
end else begin
--Copy temp attachments to sysmail_attachments
INSERT INTO sysmail_attachments(mailitem_id, filename, filesize, attachment)
SELECT @mailitem_id, filename, filesize, attachment
FROM sysmail_attachments_transfer
WHERE uid = @temp_table_uid
end
END `这做同样的事情,但是如果在过程调用中使用@ANSI_Attachment =1,它在发送之前删除unicode BOM标记。
查看了该解决方案here
https://stackoverflow.com/questions/15917630
复制相似问题