Pregunta

Estoy usando sp_send_dbmail en SQL2005 a enviar un correo electrónico con los resultados en un archivo adjunto.Cuando el adjunto es enviado se UCS-2 Codificados, quiero que sea ANSI o UTF-8.

Aquí está el 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

He visto algunos comentarios en internet que este se fija con sql2005 SP2, pero no se encuentra ser el caso.

¿Fue útil?

Solución

Creo que la única manera de conseguir alrededor de lo que están viendo es el uso de BCP para el volcado de los datos a un archivo plano y, a continuación, adjuntar el archivo.Lo siento, no podía ser de más ayuda.:(

Otros consejos

después de algunas investigaciones en SQL Server 2008 R2:

  1. añadir a sp_send_dbmail @ANSI_Attachment BIT = 0 CON EJECUTAR COMO 'dbo'

  2. reemplazar

    SI(@AttachmentsExist = 1) COMENZAR .......FINAL

con:

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

Con el fin de tener el archivo ANSI/UTF-8

alterar el sp_send_dbmail que vive en el msdb con esta línea junto con el resto de variables: @ANSI_Attachment BIT = 0 es decir,

@mailitem_id INT = NULL OUTPUT,
     @ANSI_Attachment BIT = 0
     WITH EXECUTE AS 'dbo'

y, a continuación, añadir esta línea a su llamada a sp_send_dbmail:

@ansi_attachment = 1

a continuación, debe darle una ansi adjunto en lugar de unicode.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top