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';
What's going wrong?
I tried various parameters value, but no result: the attachment is not deployed.