BUG: Xp_sendmail with Attachment Option Does Not Include All Results in Attachment (317797)
The information in this article applies to:
- Microsoft SQL Server 2000 (all editions)
This article was previously published under Q317797
BUG #: 353742 (SHILOH_BUGS)
SYMPTOMS
If you run the xp_sendmail extended stored procedure with the @attach_results parameter set to "TRUE", all results may not be in the attachment if:
- You call a stored procedure in the @query parameter.
-and-
- You use PRINT statements in the stored procedure you call in the @query parameter.
Some of the results may be in the message body instead of the attachment.
CAUSE
The xp_sendmail extended stored procedure does not correctly handle the output from the PRINT statements in the stored procedure.
WORKAROUND
To work around this behavior, you can use any one of the following methods:
- Set the NOCOUNT session parameter to OFF for the stored procedure, and then insert a single PRINT statement to include a line break in the beginning of the body:
PRINT '' -- two single quotes, not a double quote
The xp_sendmail extended stored procedure includes the PRINT results in the attachment correctly.
- Do not call a stored procedure in the @query parameter. Place all the statements directly in the @query parameter instead.
- If possible, use SELECT statements instead of PRINT statements. The appearance of the results may look different and dashed lines may be inserted. For example, create a stored procedure in the pubs database and call the stored procedure in the @query parameter of the xp_sendmail extended stored procedure:
USE Pubs
GO
CREATE PROCEDURE dbo.procGetAuthor
@mysel NVARCHAR(30)
AS
SET NOCOUNT ON
SELECT '** Date: ' + convert(char(30), getdate(), 109)
SELECT '' As [**********************************************************************]
SELECT au_lname, au_fname
FROM dbo.authors
WHERE au_lname like @mysel
GO
EXEC master..xp_sendmail @recipients = 'someone@example.com',
@query = 'exec Pubs..procGetAuthor [gr%]',
@subject = 'SQL Server Report',
@message = 'The information you requested from Authors table',
@attach_results = 'TRUE',
@width = 250
STATUSMicrosoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.
Modification Type: | Major | Last Reviewed: | 10/3/2003 |
---|
Keywords: | kbBug kbpending KB317797 kbAudDeveloper |
---|
|