sp send dbmail - SQL Server sp_send_dbmail procedure - Stack Overflow

admin2025-04-27  3

I'm using a SQL Server 2022 Developer edition, installed on a Windows 2022 virtual machine running on MS Virtual PC.

I'm experiencing this strange problem with the sp_send_dbmail procedure. I've written this code:

declare @outputstring AS varchar(MAX) = '';

SELECT @outputstring += concat([id],  ';', [nome],';', [data] , ';', char(13), char(10))
FROM [dbo].[tblEventi]  
WHERE YEAR(data) BETWEEN 1980 AND 1985;  

PRINT @outputstring;

EXEC msdb.dbo.sp_send_dbmail
          @profile_name = 'InvioPosta','
          @recipients = '[email protected]','
          @query = 'SELECT [id], [nome], [data]
                    FROM [dbo].[tblEventi]
                    WHERE YEAR(data) BETWEEN 1980 AND 1985',
          @query_result_header = 1,
          @query_result_separator = ';',
          @execute_query_database = 'xxxxx',
          @append_query_error = 1,
          @query_result_no_padding = 1,
          @subject = 'mail subject',
          @body = @outputstring,
          @attach_query_result_as_file = 1,
          @query_attachment_filename = 'Tabella.csv';
  • The mail is sent correctly
  • The mail is deployed to the mail client correctly
  • The mail body is correctly compiled
  • But... I get no attachment and no errors

What's going wrong?

I tried various parameters value, but no result: the attachment is not deployed.

转载请注明原文地址:http://anycun.com/QandA/1745707027a91099.html