sp_send_dbmail 在 256 个字符处截断行

sp_send_dbmail truncate rows at 256 characters

我想使用 sp_send_dbmail.

通过 e-mail 在 HTML 消息的 body 中发送查询结果

table ##HTML_BODY 的(唯一)列 [HTML_body] (nvarchar(max)) 包含一行样式,一行用于 table 标题和一行table 的每一行的行。 table 包含 10 行,每行长度为 500-650 个字符。

我使用以下:

EXEC msdb.dbo.sp_send_dbmail 
            @profile_name = 'ProfileMail'
            ,@recipients = 'me@mycompanydomain.domain'
            ,@subject = 'MySubject'
            ,@body = 'These are the values'
            ,@body_format = 'HTML'
            ,@query_result_width = 2000
            ,@query = ' SET NOCOUNT ON SELECT [HTML_body] FROM ##HTML_BODY SET NOCOUNT OFF'
            ,@file_attachments='\ThePath\Graph.jpg'
            ,@attach_query_result_as_file = 0
            ,@query_result_separator = '|'
            ,@exclude_query_output = 1
            ,@query_result_no_padding = 1
            ,@query_result_header = 0
            ,@append_query_error=1

代码有效,但每一行都在 256 个字符后被截断...任何人都知道可能是什么问题吗? 我已经明确 @query_result_width 应该是 2000!

我正在使用 SQL Server 9.0.4035 (2005),但没有找到任何关于 @query_result_width.

兼容性的信息

更新

我在使用 SQL Server 12.0.2000 (2014)

时遇到了同样的问题

您需要使用 @query_no_truncate = 1 因为 nvarchar(max)

我的粗体来自the docs

[ @query_no_truncate= ] query_no_truncate
Specifies whether to execute the query with the option that avoids truncation of large variable length data types (varchar(max), nvarchar(max), varbinary(max), xml, text, ntext, image, and user-defined data types). When set, query results do not include column headers. The query_no_truncate value is of type bit. When the value is 0 or not specified, columns in the query truncate to 256 characters. When the value is 1, columns in the query are not truncated. This parameter defaults to 0.