I am using sp_send_dbmail in SQL2005 to send an email with the results in an attachment. When the attachment is sent it is UCS-2 Encoded, I want it to be ANSI or UTF-8.
Here is the SQL
EXEC msdb.dbo.sp_send_dbmail
@recipients = 'temp@example.com'
, @query = 'DECLARE @string_to_trim varchar(60);SET @string_to_trim = ''1234''; select rtrim(@string_to_trim), ''tom'''
, @query_result_header=0
, @subject = 'see attach'
, @body= 'temp body'
, @profile_name= N'wksql01tAdmin'
, @body_format = 'HTML'
,@query_result_separator = ','
,@query_attachment_filename = 'results.csv'
,@query_no_truncate = '0'
,@attach_query_result_as_file = 1
I have seen some comments on the internet that this is fixed with sql2005 SP2, but do not find it to be the case.
I think the only way to get around what you are seeing is to use BCP to dump the data to a flat file and then attach that file. Sorry I couldn't be more help. :(
After some research on SQL Server 2008 R2:
Add to
sp_send_dbmail
:Replace
with:
In order to have the file be ANSI/UTF-8
alter the sp_send_dbmail that lives in the
msdb
with this line along with the other variables:@ANSI_Attachment BIT = 0
i.e.and then add this line to your call to sp_send_dbmail:
then it should give you an ansi attachment instead of unicode.